我最近下载了英语的fasttext预训练模型.我有两个文件:
我不确定这两个文件有什么区别?
我想了解创建句子的 fastText 向量的方式。根据这个问题309,通过平均单词的向量来获得句子的向量。
为了确认这一点,我编写了以下脚本:
import numpy as np
import fastText as ft
# Loading model for Finnish.
model = ft.load_model('cc.fi.300.bin')
# Getting word vectors for 'one' and 'two'.
one = model.get_word_vector('yksi')
two = model.get_word_vector('kaksi')
# Getting the sentence vector for the sentence "one two" in Finnish.
one_two = model.get_sentence_vector('yksi kaksi')
one_two_avg = (one + two) / 2
# Checking if the two approaches yield the same result.
is_equal = np.array_equal(one_two, one_two_avg)
# Printing the result.
print(is_equal)
# Result: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用FastText Python API https://pypi.python.org/pypi/fasttext虽然,根据我的阅读,此API无法加载较新的.bin模型文件https:// github .ps/facebookresearch/fastText/blob/master/pretrained-vectors.md,如https://github.com/salestock/fastText.py/issues/115中所述
我已经尝试了在该问题上建议的所有内容,而且https://github.com/Kyubyong/wordvectors没有.bin用于英语,否则问题将得到解决.有没有人知道这方面的解决方法?
我正在玩FastText,https: //pypi.python.org/pypi/fasttext 非常相似FastText
.因为它似乎是一个非常新的库,但还没有很多内置函数.我想知道如何提取形态相似的词,例如:Word2Vec
- >狗.但是没有内置的功能.
如果我输入model.similar_word("dog")
I只获得向量,那可能用于比较余弦相似度model["dog"]
.我是否必须进行某种循环并对model.cosine_similarity(model["dog"], model["dogs"]])
文本中所有可能的对进行操作?那需要时间......
我正在研究文本分类问题,也就是说,给定一些文本,我需要为其分配某些给定的标签.
我尝试过使用Facebook的快速文本库,它有两个我感兴趣的实用工具:
A)具有预训练模型的单词向量
B)文本分类实用程序
但是,似乎这些是完全独立的工具,因为我无法找到合并这两个实用程序的任何教程.
我想要的是能够通过利用Word-Vectors的预训练模型对某些文本进行分类.有没有办法做到这一点?
我已经下载了一个.bin
FastText 模型,并按gensim
如下方式使用它:
model = FastText.load_fasttext_format("cc.fr.300.bin")
Run Code Online (Sandbox Code Playgroud)
我想继续训练模型以使其适应我的领域。经过检查FastText的Github上和Gensim文档看起来它是不是利用这个人的提议目前可行的APPART修改(尚未合并)。
我错过了什么吗?
我无法运行文档中所示的FastText量化。具体来说,如备忘单页面底部所示:
https://fasttext.cc/docs/en/cheatsheet.html
当我尝试在训练有素的模型“ model.bin”上运行量化时:
./fasttext quantize -output model
Run Code Online (Sandbox Code Playgroud)
将以下错误打印到外壳:
Empty input or output path.
Run Code Online (Sandbox Code Playgroud)
我已经用最新代码(2018年9月14日)和较旧的代码(2018年6月21日)的版本重现了此问题。由于记录的命令语法不起作用,因此我尝试添加输入参数:
./fasttext quantize -input [file] -output model
Run Code Online (Sandbox Code Playgroud)
其中[文件]是我的训练数据或训练的模型。不幸的是,这两次尝试都导致了分割错误,并且没有来自FastText的错误消息。
量化FastText模型的正确命令语法是什么?此外,是否可以在一次FastText运行中同时训练和量化模型?
我使用fasttext.train_unsupervised()
python 中的函数训练了我的无监督模型。我想将它保存为 vec 文件,因为我将使用此文件作为pretrainedVectors
函数中的参数fasttext.train_supervised()
。pretrainedVectors
只接受 vec 文件,但我在创建这个 vec 文件时遇到了麻烦。有人能帮我吗?
附言。我能够以 bin 格式保存它。如果您建议我一种将 bin 文件转换为 vec 文件的方法,这也会很有帮助。
我正在使用预先训练的快速文本模型https://github.com/facebookresearch/fastText/blob/master/pretrained-vectors.md).
我使用Gensim加载fasttext模型.它可以输出任何单词的向量,无论它是被看到还是看不见(词汇外).
from gensim.models.wrappers import FastText
en_model = FastText.load_fasttext_format('../wiki.en/wiki.en')
print(en_model['car'])
print(en_model['carcaryou'])
Run Code Online (Sandbox Code Playgroud)
在张量流中,我知道我可以使用下面的代码来获得所见单词的可训练嵌入:
# Embedding layer
embeddings = tf.get_variable('embedding_matrix', [vocab_size, state_size], Trainable=True)
rnn_inputs = tf.nn.embedding_lookup(embeddings, x)
Run Code Online (Sandbox Code Playgroud)
已知单词的索引很容易获得.然而,对于那些看不见的词,FastText基于子词模式"预测"它们的潜在向量.看不见的单词没有任何索引.
在这种情况下,我应该如何使用tensorflow来处理已知单词和使用fasttext的看不见的单词?
我尝试fasttext
使用两个渠道通过 conda安装:
conda install -c conda-forge fasttext
和
conda install -c conda-forge/label/cf201901 fasttext
根据(https://anaconda.org/conda-forge/fasttext)。
我正在使用以下命令导入:import fasttext
但是,导入失败并显示错误:
ModuleNotFoundError Traceback (最近一次调用最后一次) in ----> 1 import fasttext
ModuleNotFoundError: 没有名为“fasttext”的模块
但是,尝试以较旧的方式导入它import fastText
,但失败了。
已经尝试过的python
和python3
,这两者的失败。
我想避免使用安装它pip
并使用conda
.
conda list
显示fasttext
正在安装。其输出如下所示:
fasttext 0.2.0 hfc679d8_1 conda-forge/label/cf201901
的输出python -c 'import sys; print(sys.path)
如下:
['', '/<dir>/<dir>/anaconda3/lib/python37.zip', '/<dir>/<dir>/anaconda3/lib/python3.7', '/<dir>/<dir>/anaconda3/lib/python3.7/lib-dynload', '/<dir>/<dir>/anaconda3/lib/python3.7/site-packages']