情感分析和快速文本:导入错误

问题描述 投票:0回答:1

我想用 FastText. 然而,我在声明库的过程中总是出错,而网络上的任何例子和教程似乎都无法解决这个问题。

我试着按照这里描述的步骤去做。https:/github.comfacebookresearchfastTexttreemasterpython#安装。

但自始至终,即自

import fasttext
from fasttext import train_unsupervised

我一直得到以下错误。

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-10-193c2ffe3856> in <module>
      1 import fasttext
----> 2 from fasttext import train_unsupervised
      3 
      4 # Skipgram model :
      5 model = fasttext.train_unsupervised('data.txt', model='skipgram')

ImportError: cannot import name 'train_unsupervised' from 'fasttext' (/anaconda3/lib/python3.7/site-packages/fasttext/__init__.py)

我在Jupyter Notebook中使用Python 3.7。我需要FastText来分析一些意大利文本的情感。我去了这里。https:/fasttext.cdocsensupervised-models.html。 但我一直不明白我应该下载什么。

我真的希望你能帮我解决这个问题。

python sentiment-analysis fasttext
1个回答
1
投票

在干净的Python 3.7 conda环境下运行你的代码,在用pip安装fasttext后应该可以用(pip install fasttext).

如果你这样做,你应该在Linux控制台中看到带有

pip list | grep fasttext

你的 fasttext 版本是0.9.2(今天的版本)。

此外,在安装 wget 包,下面的代码应该可以让你开始使用你链接的页面中的一个训练模型(亚马逊评论)进行情感分析。

import wget
from fasttext import load_model

wget.download("https://dl.fbaipublicfiles.com/fasttext/supervised-models/amazon_review_polarity.bin", 'model.bin')

model = load_model("model.bin")

model.predict("This movie sucks") # see how output changes!
model.predict("This band is great")
model.predict("I just feel OK about this.") 

如果模型的大小是个问题,可以尝试用一个压缩的模型来替换。

wget.download("https://dl.fbaipublicfiles.com/fasttext/supervised-models/amazon_review_polarity.ftz", 'model.ftz')

model = load_model("model.ftz")

你也可以参考 https:/fasttext.cdocsensupervised-tutorial.html。 以代替在自定义数据集上训练模型。

© www.soinside.com 2019 - 2024. All rights reserved.