SpaCy 字符串存储

数据挖掘 nlp 斯派西
2022-03-15 05:57:51

我正在尝试从 SpaCy 的字符串存储中获取一些英语单词的哈希值。

nlp = English()
doc1 = nlp('this is doc1')
id = doc1.vocab.strings['Saurabh']
print(id)
# output, it has given hash code

id1 = doc1.vocab.strings['समाचार'] 
# This is a hindi word so i do not expect it to be a part of English,
# so it shoud throw an error.
print(id1)
# output, it given hash code

为什么这在(至少)第二行没有给出错误?

1个回答

Spacy 使用哈希函数将整数分配给任何 Unicode 字符串,它不是词汇表中的索引,它只是内部使用的随机整数,以提高效率。它是一个哈希函数,所以这意味着冲突确实是可能的,但不太可能也很少对库的准确性产生负面影响,因此效率收益超过它。