通过Fasttext学习单词表示:使用子词信息丰富单词向量。
该模块允许从训练语料库中训练单词嵌入,并具有获得词汇外单词的单词向量的附加能力。
该模块包含带有Python接口的Fasttext的快速本机C实现。这是不是只是围绕Facebook的实施包装。
该模块支持加载使用Facebook的fastText实现训练的模型。它还支持这些模型的持续培训。
有关教程,请参阅此笔记本。
在安装Gensim之前确保你有一个C编译器,以使用优化(编译)的Fasttext训练例程。
用法示例
初始化并训练模型:
>>> # from gensim.models import FastText # FIXME: why does Sphinx dislike this import?
>>> from gensim.test.utils import common_texts # some example sentences
>>>
>>> print(common_texts[0])
['human', 'interface', 'computer']
>>> print(len(common_texts))
9
>>> model = FastText(size=4, window=3, min_count=1) # instantiate
>>> model.build_vocab(sentences=common_texts)
>>> model.train(sentences=common_texts, total_examples=len(common_texts), epochs=10) # train
拥有模型后,您可以通过model.wv属性访问其键控向量。键控向量实例非常强大:它可以执行各种NLP任务。有关示例的完整列表,请参阅FastTextKeyedVectors
。
您还可以将所有上述参数传递给构造函数,以便在一行中执行所有操作:
>>> model2 = FastText(size=4, window=3, min_count=1, sentences=common_texts, iter=10)
重要
这种初始化和训练的风格在一行中已被弃用。我们将其包含在此处仅用于向后兼容。
请使用initialize- build_vocab - 列车图案上方代替,包括使用历元 代替ITER。其动机是简化API并解决命名不一致问题,例如构造函数的iter参数在train函数中称为epochs。
上述两个模型的实例化方式不同,但行为相同。例如,我们可以比较他们为“计算机”这个词计算的嵌入:
>>> import numpy as np
>>>
>>> np.allclose(model.wv['computer'], model2.wv['computer'])
True
在上面的例子中,我们从加载到存储器中的句子(单词列表)中训练模型。这对于较小的数据集是可以的,但对于较大的数据集,我们建议流式传输文件,例如从磁盘或网络。在Gensim中,我们将这样的数据集称为“语料库”(单数“语料库”),并将它们保持在描述的格式中LineSentence
。传递语料库很简单:
>>> from gensim.test.utils import datapath
>>>
>>> corpus_file = datapath('lee_background.cor') # absolute path to corpus
>>> model3 = FastText(size=4, window=3, min_count=1)
>>> model3.build_vocab(corpus_file=corpus_file) # scan over corpus to build the vocabulary
>>>
>>> total_words = model3.corpus_total_words # number of words in the corpus
>>> model3.train(corpus_file=corpus_file, total_words=total_words, epochs=5)
该模型需要total_words参数才能正确管理训练率(alpha),并提供准确的进度估计。上面的示例依赖于实现细节:该 build_vocab()
方法设置corpus_total_words(以及corpus_count)模型属性。您也可以通过自己扫描语料库来计算它们。
如果您有不同格式的语料库,则可以通过将其包装在迭代器中来使用它。您的迭代器应该每次都产生一个字符串列表,其中每个字符串应该是一个单独的单词。Gensim将负责其余的事情:
>>> from gensim.utils import tokenize
>>> import smart_open
>>>
>>>
>>> class MyIter(object):
... def __iter__(self):
... path = datapath('crime-and-punishment.txt')
... with smart_open.smart_open(path, 'r', encoding='utf-8') as fin:
... for line in fin:
... yield list(tokenize(line))
>>>
>>>
>>> model4 = FastText(size=4, window=3, min_count=1)
>>> model4.build_vocab(sentences=MyIter())
>>> total_examples = model4.corpus_count
>>> model4.train(sentences=MyIter(), total_examples=total_examples, epochs=5)
将模型保留到磁盘:
>>> from gensim.test.utils import get_tmpfile
>>>
>>> fname = get_tmpfile("fasttext.model")
>>>
>>> model.save(fname)
>>> model = FastText.load(fname)
加载后,此类模型的行为与从头创建的模型相同。例如,您可以继续训练加载的模型:
>>> import numpy as np
>>>
>>> 'computation' in model.wv.vocab # New word, currently out of vocab
False
>>> old_vector = np.copy(model.wv['computation']) # Grab the existing vector
>>> new_sentences = [
... ['computer', 'aided', 'design'],
... ['computer', 'science'],
... ['computational', 'complexity'],
... ['military', 'supercomputer'],
... ['central', 'processing', 'unit'],
... ['onboard', 'car', 'computer'],
... ]
>>>
>>> model.build_vocab(new_sentences, update=True) # Update the vocabulary
>>> model.train(new_sentences, total_examples=len(new_sentences), epochs=model.epochs)
>>>
>>> new_vector = model.wv['computation']
>>> np.allclose(old_vector, new_vector, atol=1e-4) # Vector has changed, model has learnt something
False
>>> 'computation' in model.wv.vocab # Word is still out of vocab
False
重要
在继续训练的方法之前,请务必build_vocab()
使用update = True调用方法train()
。如果没有此调用,以前看不见的术语将不会添加到词汇表中。
您还可以加载使用Facebook的fastText实现训练的模型:
>>> cap_path = datapath("crime-and-punishment.bin")
>>> # Partial model: loads quickly, uses less RAM, but cannot continue training
>>> fb_partial = FastText.load_fasttext_format(cap_path, full_model=False)
>>> # Full model: loads slowly, consumes RAM, but can continue training (see below)
>>> fb_full = FastText.load_fasttext_format(cap_path, full_model=True)
一旦加载,这些模型的行为与从头开始训练的模型相同。您可以继续培训新数据:
>>> 'computer' in fb_full.wv.vocab # New word, currently out of vocab
False
>>> old_computer = np.copy(fb_full.wv['computer']) # Calculate current vectors
>>> fb_full.build_vocab(new_sentences, update=True)
>>> fb_full.train(new_sentences, total_examples=len(new_sentences), epochs=model.epochs)
>>> new_computer = fb_full.wv['computer']
>>> np.allclose(old_computer, new_computer, atol=1e-4) # Vector has changed, model has learnt something
False
>>> 'computer' in fb_full.wv.vocab # New word is now in the vocabulary
True
检索词汇和词汇词的单词矢量:
>>> existent_word = "computer"
>>> existent_word in model.wv.vocab
True
>>> computer_vec = model.wv[existent_word] # numpy vector of a word
>>>
>>> oov_word = "graph-out-of-vocab"
>>> oov_word in model.wv.vocab
False
>>> oov_vec = model.wv[oov_word] # numpy vector for OOV word
您可以使用模型执行各种NLP字任务,其中一些已经内置:
>>> similarities = model.wv.most_similar(positive=['computer', 'human'], negative=['interface'])
>>> most_similar = similarities[0]
>>>
>>> similarities = model.wv.most_similar_cosmul(positive=['computer', 'human'], negative=['interface'])
>>> most_similar = similarities[0]
>>>
>>> not_matching = model.wv.doesnt_match("human computer interface tree".split())
>>>
>>> sim_score = model.wv.similarity('computer', 'human')
与人类对词语相似性的看法相关:
>>> from gensim.test.utils import datapath
>>>
>>> similarities = model.wv.evaluate_word_pairs(datapath('wordsim353.tsv'))
在单词类比上:
>>> analogies_result = model.wv.evaluate_word_analogies(datapath('questions-words.txt'))
实施说明
这些说明可以帮助开发人员导航我们的fastText实现。该实现分为几个子模块:
gensim.models.fasttext
:这个模块。仅包含FastText特定功能。gensim.models.keyedvectors
:实现泛型和特定于FastText的功能。gensim.models.word2vec
:包含FastText的词汇表和trainables的实现。gensim.models.base_any2vec
:包含基础的实现。类,包括回调,日志记录等功能。gensim.models.utils_any2vec
:Cython扩展包装器。gensim.utils
:实现模型I / O(加载和保存)。
我们的实现很大程度上依赖于继承。它由几个重要的类组成:
Word2VecVocab
: 词汇。跟踪所有独特的单词,有时会丢弃极为罕见的单词。这有时被称为Gensim中的字典。FastTextKeyedVectors
:向量。训练完成后,此类足以计算嵌入。FastTextTrainables
:潜在的神经网络。该实现使用此类来学习嵌入一词。FastText
:将一切联系在一起。
class gensim.models.fasttext.
FastText
(sentences = None,corpus_file = None,sg = 0,hs = 0,size = 100,alpha = 0.025,window = 5,min_count = 5,max_vocab_size = None,word_ngrams = 1,sample = 0.001,seed = 1,workers = 3,min_alpha = 0.0001,negative = 5,ns_exponent = 0.75,cbow_mean = 1,hashfxn = <内置函数hash>,iter = 5,null_word = 0,min_n = 3,max_n = 6,sorted_vocab = 1,bucket = 2000000,trim_rule = None,batch_words = 10000,callbacks =(),compatible_hash = True )
基地: gensim.models.base_any2vec.BaseWordEmbeddingsModel
训练,使用和评估使用富含Word字母向量和子字信息(又名FastText)中描述的方法学习的单词表示。
该模型可以被存储/经由其加载save()
和 load()
方法,或从经由原始Fasttext实施兼容的格式加载load_fasttext_format()
。
wv
该对象基本上包含单词和嵌入之间的映射。这些类似于计算的嵌入Word2Vec
,但是在这里我们还包括n-gram的向量。这允许模型计算嵌入甚至对于看不见的单词(在词汇表中不存在),作为单词中包含的n-gram的集合。训练模型后,可以直接使用此属性以各种方式查询这些嵌入。查看模块级docstring以获取一些示例。
类型: | FastTextKeyedVectors |
---|
vocabulary
该对象表示模型的词汇表。除了跟踪所有独特单词之外,该对象还提供额外的功能,例如构建一个霍夫曼树(频繁的单词更接近根),或丢弃极其罕见的单词。
类型: | FastTextVocab |
---|
trainables
该对象表示用于训练嵌入的内部浅层神经网络。这与Word2Vec
模型的网络非常相似,但它也训练N-Grams的权重(超过1个单词的序列)。网络的语义几乎与用于Word2Vec
模型的语义相同。您可以将其视为具有单个投影和隐藏层的NN,我们在语料库上进行训练。然后将权重用作嵌入。然而,两个模型之间的一个重要区别是用于计算损失的评分函数。在FastText的情况下,除了它们的并发计数之外,还会在单词中对其进行修改以考虑单词的内部结构。
类型: | FastTextTrainables |
---|
参数: |
|
---|
例子
初始化并训练FastText模型:
>>> from gensim.models import FastText
>>> sentences = [["cat", "say", "meow"], ["dog", "say", "woof"]]
>>>
>>> model = FastText(sentences, min_count=1)
>>> say_vector = model.wv['say'] # get vector for word
>>> of_vector = model.wv['of'] # get vector for out-of-vocab word
__getitem__
(** kwargs )
已过时。请改用self.wv .__ getitem __()。
请参阅文档 gensim.models.keyedvectors.KeyedVectors.__getitem__()
accuracy
(** kwargs )
bucket
build_vocab
(sentences = None,corpus_file = None,update = False,progress_per = 10000,keep_raw_vocab = False,trim_rule = None,** kwargs )
从一系列句子构建词汇表(可以是一次性的生成器流)。每个句子必须是一个unicode字符串列表。
参数: |
|
---|
例子
培训模型并更新在线培训词汇:
>>> from gensim.models import FastText
>>> sentences_1 = [["cat", "say", "meow"], ["dog", "say", "woof"]]
>>> sentences_2 = [["dude", "say", "wazzup!"]]
>>>
>>> model = FastText(min_count=1)
>>> model.build_vocab(sentences_1)
>>> model.train(sentences_1, total_examples=model.corpus_count, epochs=model.epochs)
>>>
>>> model.build_vocab(sentences_2, update=True)
>>> model.train(sentences_2, total_examples=model.corpus_count, epochs=model.epochs)
build_vocab_from_freq
(word_freq,keep_raw_vocab = False,corpus_count = None,trim_rule = None,update = False )
从词频词典中构建词汇。
参数: |
|
---|
clear_sims
()
从模型中删除所有L2标准化的单词向量,以释放内存。
您可以稍后使用该init_sims()
方法重新计算它们。
cum_table
doesnt_match
(** kwargs )
不推荐使用,请改用self.wv.doesnt_match()。
请参阅文档doesnt_match()
。
estimate_memory
(vocab_size =无,报告=无)
使用当前设置和提供的词汇量大小估算模型所需的内存。
参数: |
|
---|---|
返回: | 从模型的内存消耗成员的字符串表示到其大小(以字节为单位)的字典。 |
返回类型: | (str,int)的字典 |
evaluate_word_pairs
(** kwargs )
不推荐使用,请改用self.wv.evaluate_word_pairs()。
请参阅文档 evaluate_word_pairs()
。
hashfxn
init_sims
(replace = False )
预计算L2标准化向量。
参数: | replace(bool) - 如果为True,则忘记原始向量,只保留标准化向量以节省RAM。 |
---|
iter
layer1_size
classmethod load
(* args,** kwargs )
加载以前保存的FastText模型。
参数: | fname(str) - 保存文件的路径。 |
---|---|
返回: | 加载模型。 |
返回类型: | FastText |
也可以看看
保存FastText
模型。
load_binary_data
(encoding ='utf8' )
从Facebook的本机FastText创建的二进制文件加载数据。
参数: | encoding(str ,optional) - 指定编码。 |
---|
classmethod load_fasttext_format
(model_file,encoding ='utf8',full_model = True )
从Facebook的原生fasttext .bin和.vec输出文件加载输入隐藏权重矩阵。
默认情况下,此函数会加载完整模型。完整模型允许继续训练更多数据,但也消耗更多RAM并且加载时间更长。如果您不需要继续训练并且只希望使用已经训练过的嵌入工作,请使用full_model = False 以加快加载速度并节省RAM。
笔记
Facebook提供.vec和.bin文件及其模块。前者包含人类可读的载体。后者包含机器可读矢量以及其他模型参数。此函数有效地忽略.vec输出文件,因为该文件是多余的。它只需要.bin文件。
参数: |
|
---|
例子
加载,推断,继续训练:
>>> from gensim.test.utils import datapath
>>>
>>> cap_path = datapath("crime-and-punishment.bin")
>>> fb_full = FastText.load_fasttext_format(cap_path, full_model=True)
>>>
>>> 'landlord' in fb_full.wv.vocab # Word is out of vocabulary
False
>>> oov_term = fb_full.wv['landlord']
>>>
>>> 'landlady' in fb_full.wv.vocab # Word is in the vocabulary
True
>>> iv_term = fb_full.wv['landlady']
>>>
>>> new_sent = [['lord', 'of', 'the', 'rings'], ['lord', 'of', 'the', 'flies']]
>>> fb_full.build_vocab(new_sent, update=True)
>>> fb_full.train(sentences=new_sent, total_examples=len(new_sent), epochs=5)
快速加载,推断(放弃训练延续):
>>> fb_partial = FastText.load_fasttext_format(cap_path, full_model=False)
>>>
>>> 'landlord' in fb_partial.wv.vocab # Word is out of vocabulary
False
>>> oov_term = fb_partial.wv['landlord']
>>>
>>> 'landlady' in fb_partial.wv.vocab # Word is in the vocabulary
True
>>> iv_term = fb_partial.wv['landlady']
返回: | 加载的模型。 |
---|---|
返回类型: | gensim.models.fasttext.FastText |
max_n
min_count
min_n
most_similar
(** kwargs )
不推荐使用,请改用self.wv.most_similar()。
请参阅文档most_similar()
。
most_similar_cosmul
(** kwargs )
不推荐使用,请改用self.wv.most_similar_cosmul()。
请参阅文档 most_similar_cosmul()
。
n_similarity
(** kwargs )
不推荐使用,请改用self.wv.n_similarity()。
请参阅文档n_similarity()
。
num_ngram_vectors
sample
save
(* args,** kwargs )
保存Fasttext模型。这个保存的模型可以再次使用 load()
,它支持增量训练和获取词汇外单词的向量。
参数: | fname(str) - 将模型存储到此文件中。 |
---|
也可以看看
加载FastText
模型。
similar_by_vector
(** kwargs )
不推荐使用,请改用self.wv.similar_by_vector()。
请参阅文档similar_by_vector()
。
similar_by_word
(** kwargs )
不推荐使用,请改用self.wv.similar_by_word()。
请参阅文档similar_by_word()
。
similarity
(** kwargs )
不推荐使用,请改用self.wv.similarity()。
请参阅文档similarity()
。
syn0_lockf
syn0_ngrams_lockf
syn0_vocab_lockf
syn1
syn1neg
train
(句子=无,corpus_file =无,total_examples =无,total_words =无,历元=无,start_alpha =无,end_alpha =无,WORD_COUNT = 0,queue_factor = 2,report_delay = 1.0,回调=() ,** kwargs )
从一系列句子更新模型的神经权重(可以是只有一次的生成器流)。对于FastText,每个句子必须是unicode字符串列表。
为了支持从(初始)线性学习速率衰变阿尔法到min_alpha,和准确的进度百分比的日志记录,或者total_examples(句子的计数)或total_words(在句子的原始词数)必须被提供。如果句子与build_vocab()
之前提供的语料库相同,则可以使用total_examples = self.corpus_count。
为避免模型能够自行进行多次训练的常见错误,必须提供明确的epochs参数。在常见和推荐的情况下,只调用一次,您可以设置epochs = self.iter。train()
参数: |
|
---|
例子
>>> from gensim.models import FastText
>>> sentences = [["cat", "say", "meow"], ["dog", "say", "woof"]]
>>>
>>> model = FastText(min_count=1)
>>> model.build_vocab(sentences)
>>> model.train(sentences, total_examples=model.corpus_count, epochs=model.epochs)
wmdistance
(** kwargs )
不推荐使用,请改用self.wv.wmdistance()。
请参阅文档wmdistance()
。
class gensim.models.fasttext.
FastTextTrainables
(vector_size = 100,seed = 1,hashfxn = <内置函数hash>,bucket = 2000000 )
基地: gensim.models.word2vec.Word2VecTrainables
代表用于训练的内部浅层神经网络FastText
。
大部分都是从其parent(Word2VecTrainables
)继承的。添加用于计算和维护ngram权重的逻辑。
hashfxn
用于随机初始化权重。默认为内置哈希()
类型: | 功能 |
---|
layer1_size
NN内层的大小。等于矢量维度。在Word2VecTrainables
构造函数中设置。
类型: | INT |
---|
seed
在reset_weights和update_weights中使用的随机生成器种子。
类型: | 浮动 |
---|
syn1
NN的内层。每行对应于词汇表中的术语。列对应于内层的权重。有layer1_size这样的权重。仅在使用分层采样时,在reset_weights和update_weights方法中设置。
类型: | numpy.array |
---|
syn1neg
与syn1类似,但仅在使用负采样时设置。
类型: | numpy.array |
---|
vectors_lockf
一个一维数组,每个术语中有一个元素。在reset_weights中设置为1的数组。
类型: | numpy.array |
---|
vectors_vocab_lockf
与vectors_vocab_lockf类似,有些(len(model.trainables.vectors),dtype = REAL)
类型: | numpy.array |
---|
vectors_ngrams_lockf
np.ones((self.bucket,wv.vector_size),dtype = REAL)
类型: | numpy.array |
---|
init_ngrams_weights
(wv,update = False,词汇=无)
计算词汇表中存在的所有单词的ngrams并仅存储那些ngram的向量。其他ngrams的向量在FastText中使用随机均匀分布进行初始化。
参数: |
|
---|
init_post_load
(model,hidden_output )
classmethod load
(fname,mmap = None )
加载以前使用save()
文件保存的对象。
参数: |
|
---|
也可以看看
将对象保存到文件。
返回: | 从fname加载的对象。 |
---|---|
返回类型: | 宾语 |
举: | AttributeError - 在对象实例而不是类上调用时(这是一个类方法)。 |
prepare_weights
(hs,negative,wv,update = False,词汇=无)
根据最终词汇表设置构建表格和模型权重。
reset_weights
(hs,negative,wv )
将所有投影权重重置为初始(未经训练)状态,但保留现有词汇表。
save
(fname_or_handle,separate = None,sep_limit = 10485760,ignore = frozenset([]),pickle_protocol = 2 )
将对象保存到文件。
参数: |
|
---|
也可以看看
从文件加载对象。
seeded_vector
(seed_string,vector_size )
获取随机向量(但由seed_string确定)。
update_weights
(hs,negative,wv )
复制所有现有的权重,并重置新添加的词汇表的权重。
class gensim.models.fasttext.
FastTextVocab
(max_vocab_size = None,min_count = 5,sample = 0.001,sorted_vocab = True,null_word = 0,max_final_vocab = None,ns_exponent = 0.75 )
基地: gensim.models.word2vec.Word2VecVocab
这是一个冗余类。它的存在只是为了保持与旧的gensim版本的向后兼容性。
add_null_word
(wv )
create_binary_tree
(wv )
使用存储的词汇表字数创建二进制霍夫曼树。频繁的单词将具有更短的二进制代码。从内部调用build_vocab()
。
classmethod load
(fname,mmap = None )
加载以前使用save()
文件保存的对象。
参数: |
|
---|
也可以看看
将对象保存到文件。
返回: | 从fname加载的对象。 |
---|---|
返回类型: | 宾语 |
举: | AttributeError - 在对象实例而不是类上调用时(这是一个类方法)。 |
make_cum_table
(wv,domain = 2147483647 )
使用存储的词汇表字数创建累积分布表,以便在负抽样训练例程中绘制随机字。
要绘制单词索引,请选择一个随机整数,直到表中的最大值(cum_table [-1]),然后找到整数的排序插入点(就像通过bisect_left或ndarray.searchsorted())。该插入点是绘制的索引,其比例等于该槽的增量。
从内部调用build_vocab()
。
prepare_vocab
(hs,negative,wv,update = False,keep_raw_vocab = False,trim_rule = None,min_count = None,sample = None,dry_run = False )
应用min_count的词汇表设置(丢弃不常用的词)和样本(控制更频繁词的下采样)。
使用dry_run = True调用将仅模拟提供的设置并报告保留的词汇量,有效语料库长度和估计的内存要求的大小。结果通过记录打印并作为dict返回。
除非设置了keep_raw_vocab,否则在完成缩放后删除原始词汇表以释放RAM 。
save
(fname_or_handle,separate = None,sep_limit = 10485760,ignore = frozenset([]),pickle_protocol = 2 )
将对象保存到文件。
参数: |
|
---|
也可以看看
从文件加载对象。
scan_vocab
(sentences = None,corpus_file = None,progress_per = 10000,workers = None,trim_rule = None )¶
sort_vocab
(wv )
对词汇表进行排序,使最常用的词汇具有最低的索引。
word2vec和fastText之间的主要区别是什么?
word2vec和fasttext之间的关键区别正是Trevor所提到的
- word2vec将语料库中的每个单词视为原子实体,并为每个单词生成一个向量。从这个意义上说,Word2vec非常像手套 - 它们都将单词视为最小的训练单位。参考。fastText和GloVe有什么区别?
Fasttext(基本上是word2vec模型的扩展)将每个单词视为由字符ngram组成。因此,单词的向量由该字符n的总和构成。例如,单词vector“apple”是n-gram“<ap”,“app”,“appl”,“apple”,“apple>”,“ppl”,“pple”,“pple”的向量的总和。 pple>“,”ple“,”ple>“,”le>“(假设最小ngram [minn]的超参数为3,最大ngram [maxn]为6)。这种差异表现如下。
- 为罕见的单词生成更好的单词嵌入(即使单词很少,它们的字符仍然与其他单词共享 - 因此嵌入仍然可以很好)。
- 这只是因为,在word2vec中,一个罕见的单词(例如10次出现)与被发生100次的单词相比具有更少的邻居 - 后者具有更多的邻居上下文单词,因此更频繁地被拉扯导致更好的单词向量。参考.word2vec如何工作?
- 在词汇单词中 - 即使单词没有出现在训练语料库中,它们也可以从其字符n克构造单词的向量。Word2vec和Glove都不能。
- 从实际使用的角度来看,用于生成快速文本嵌入的超参数的选择成为关键
- 由于训练处于字符n-gram级别,与word2vec相比,生成fasttext嵌入需要更长的时间 - 控制最小和最大n-gram大小的超参数的选择与此时间有直接关系。
- 随着语料库大小的增长,内存需求也会增长 - 在同一个ngram桶中散列的ngram数量会增加。因此,选择控制总哈希桶的超参数包括n-gram最小和最大大小都有影响。例如,即使256GB RAM机器也不足(交换空间明确设置得非常低以避免交换)为语料库创建单词向量,其中包含minn = 3和maxn = 3以及min字数7的约5000万个唯一词汇单词。必须将最小字数提高到15(从而丢弃大量具有小于15的字数的字)以生成字向量。
- 与使用word2vec或Glove等单词嵌入相比,最近显示用于下游任务的字符嵌入(单个字符而非n-gram)的使用提高了这些任务的性能。
- 虽然报告这些改进的论文倾向于使用字符LSTM来生成嵌入,但它们并未引用快速文本嵌入的使用。https://arxiv.org/pdf/1508.02096 ...(基于Java的此模型源代码 - wlin12 / JNN)
- 由于快速文本嵌入生成(尽管速度低于word2vec)可能比LSTM更快(这只是LSTM采取的时间 - 需要进行验证,因此可能值得考虑快速文本嵌入这些任务。例如,一个测试可以将fasttext与minn = 1,maxn = 1与corrsesponding char LSTM进行比较,并评估POS标记任务的性能)。
https://www.quora.com/What-is-the-main-difference-between-word2vec-and-fastText