2020-4-27学习记录

1.不同方式训练出来的词向量哪个效果会更好?

就上面的word和word+ngram,这能有什么区别呢?哪个效果会更好呢?

我就先用这个最简单的了,word,量比较少。

2.textRank基本原理

https://blog.csdn.net/wotui1842/article/details/80351386 待看

3.bert中怎么使用词向量呢?

先预加载一下,

4.加载预训练好的词向量

import gensim
# 导入模型  
model = gensim.models.word2vec.Word2Vec.load('sgns.weibo.word') 

# 返回一个词 的向量:
print(model[''])

首先尝试了上面这样加载,但是因为并不是使用save保存的bin文件,所以出现下面错误:

UnpicklingError: could not find MARK

https://stackoverflow.com/questions/44022180/unpickling-error-while-using-word2vec-load,这里面提到说要配套使用,文件要是model.bin这样。

https://blog.csdn.net/u010700066/article/details/83070102 这个讲了Word2VecKeyedVectors,蛮不错的!

忽然有一点懵。。。

上面的保存和加载方式是针对模型,下面的是针对单词向量,这两个类是不同的。

针对Word2VecKeyedVectors提到了,有一个属性wv:

model_w2v.wv.most_similar("民生银行")  # 找最相似的词
model_w2v.wv.get_vector("民生银行")  # 查看向量
model_w2v.wv.syn0  #  model_w2v.wv.vectors 一样都是查看向量
model_w2v.wv.vocab  # 查看词和对应向量
model_w2v.wv.index2word  # 每个index对应的词

但是我跑之后会出现以下警告:

DeprecationWarning: Call to deprecated `wv` (Attribute will be removed in 4.0.0, use self instead).

所以就直接去掉wv即可,直接用:

model.index2entity[0]
n(model.index2entity)#195202个词

5.jieba 初次尝试

import jieba
tt="2020年的第一天发烧,姨妈来难受???"
text=jieba.cut(tt)
text
#<generator object Tokenizer.cut at 0x7fd8e1757f50>
#text是一个生成器

words=[t for t in text]
words
#Building prefix dict from the default dictionary ...
#Dumping model to file cache /tmp/jieba.cache
#Loading model cost 0.694 seconds.
#Prefix dict has been built successfully.
['2020', '', '', '第一天', '发烧', '', '姨妈', '', '难受', '?', '?', '?']

分的还不错呢!

6.word2vec 如何处理未登录词

https://www.zhihu.com/question/308543084 待看

但是我目前的一个小问题是,如果我的词没有在vocab中,那这个id要映射为多少呢?这个vocab中是否有UNK呢?对于英文来说是UNK,但是对于中文来说,由哪个来表示未登录词呢?

等一下再来处理吧。

https://www.jianshu.com/p/ce630c198762

猜你喜欢

转载自www.cnblogs.com/BlueBlueSea/p/12791999.html