小编Pao*_*era的帖子

Fastai 文本分类器:对看不见的数据进行批量预测

我一直在使用 fastai 的文本分类器(https://docs.fast.ai/text.html)。我目前预测未见过的短语的情绪(正面或负面)如下:

def _unpack_prediction(self, text) -> Tuple[bool, float]:
    out = self._model.predict(text)
    return str(out[0]) == "positive", max(out[2][0].item(), out[2][1].item())

def example(self, messages: Sequence[str]):
    results = map(self._unpack_prediction, messages)
    for phrase, out in zip(messages, results):
        print(f"{phrase[:100]}...[{'pos' if out[0] else 'neg'}] - [{out[1]:.2f}]")
Run Code Online (Sandbox Code Playgroud)

给定一个短语列表:

("I love this movie",
  "The actors are good, but this movie is definitely stupid",
  "There is no plot at all!!! Just special effects ")
Run Code Online (Sandbox Code Playgroud)

结果是:

I love this movie...[pos] - [1.00]
The actors are good, but this movie …
Run Code Online (Sandbox Code Playgroud)

python deep-learning fast-ai

3
推荐指数
1
解决办法
999
查看次数

标签 统计

deep-learning ×1

fast-ai ×1

python ×1