Git Product home page Git Product logo

word-discovery's Issues

代码75-76行

您好!请问代码75-76行,对长度为m的ngram,为什么要把它的子串依次计数增加呢?count_ngrams得到的,不是已经统计好了?
image

关于total的理解为何是总字数?

以下代码摘自【中文分词系列】 8. 更好的新词发现算法

    for t in texts(" is ngraming..."):
        for i in range(len(t)):
            for j in range(1, n + 1):  # gram 1,2,3···n
                if i + j <= len(t):  # prevent overflow the length of t
                    # ngram is a huge dict,key is the word and value is the count
                    ngrams[t[i:i + j]] += 1

以8字的例句本刊感谢各位专家为例,进行ngram分词后结果为一个大小为26的dict
image
对于此问题,您给出了如下的解释:

别忘了某个句子的全体ngram是
[text[i:i + n] for i in range(len(text) - n + 1)]
所以总ngram数约等于总字数。

考虑到也许您的约等于是指数量级上的约等于, 因此下面取几个大文件对比一下

  1. 总字符数为234958742字,ngram中所有key的频次累加和为736195698
  2. 总字符数为202362720字,ngram中所有key的频次累加和为624372458
  3. 总字符数为110199596字,ngram中所有key的频次累加和为346968516

由上述局部的本刊感谢各位专家例子亦或者是大文件的例子都可以看到ngram中频次累加和均大致为数据总字数的3倍左右。但3倍在计算PMI处理的过程中会带来多大差距呢?我以1.为例,取其中最高频次的词汇企业,频次1307887,其中频次为1953603频次为3030854,该语料库总字数为212741102.0,据此所计算出的pmi=69.00695726310722,

鉴于此处变量只有total,直接将上述结果×3得到基于key的频次累加pmi大约为207

所以是觉得对于2-gram来讲20769相对于阈值5来说都大很多,所以基本差别不大这个意思么?🤣

生成的词表是单个字的形式

您好!非常感谢您分享您的工作!我按照复现的步骤在所给文本上进行测试,输出的词典文件中是单个的字而不是词请问是为什么?
输出结果如下:
167812
不 20863
一 18345
的 16298
道 15707
了 15406
是 14528
人 13219
我 11523
你 10255
他 9957
这 9885
大 9602
来 8814
之 7887
说 7455

total的计算方式,是否有问题

up主的博客中提到,可以用n为某个值的ngram总频数来计算total

事实上,根据(对于某个固定的n)ngram的计算方式: [text[i:i + n] for i in range(len(text) - n + 1)] ,就知道每种ngram的总数约等于字数是显然成立的。

而源码中,是对所有ngram的频数的总和来计算total的,是否与博客中的算法不一致,导致pmi计算不正确?
for s, n in Progress(ngrams(), 100000, desc=u'loading ngrams'):
if n >= self.min_count:
self.total += n

PMI计算的准确性问题

有个疑问,我们计算4-gram是基于我们已经计算好了2-gram以及3-gram基础之上,也就是说我们的2-gram和3-gram也是经过词频和凝固度的过滤,在过滤之后,2-gram和3-gram的总频数也就不存在约等于总次数的情况了,那么我们计算4-gram的凝固度的时候,以下式子也不成立了。
score = min([total*ngrams[s]/(ngrams[s[:i+1]]*ngrams[s[i+1:]])

程序卡住了,请问怎么解决

2022-05-08 13:21:29,202 - INFO - loading ngrams - 8200000 passed
2022-05-08 13:21:29,261 - INFO - loading ngrams - 8300000 passed
Traceback (most recent call last):
File "word_discovery.py", line 206, in
ngrams = filter_ngrams(ngrams.ngrams, ngrams.total, [0, 2, 4, 6]) # 过滤ngram
File "word_discovery.py", line 123, in filter_ngrams
if math.log(pmi) >= min_pmi[i]:
IndexError: list index out of range

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.