g2pc:一个上下文感知的中文g2p模块
g2pC的Python项目详细描述
g2pc:中文音素的上下文感知字形
有几个开放源码的中文字母音素库。 转换,如python-pinyin或xpinyin。 然而,它们似乎都没有消除汉语复调词的歧义。 (“xíng”(走,走)对“háng”(行)或“le”(完成动作标记) 对“李o”(完成,完成)。相反,他们选择了最频繁的发音。 尽管这可能是一个简单而经济的策略,但机器学习技术可能会有所帮助。 我们使用crf来确定复调词的发音。除了目标词本身和它的词性被pkuseg标记外,它的相邻词也被特殊化了。
要求
- python=3.6
- 包装
- 学习套件
安装
pip install g2pc
主要功能
- 消除复音汉字/单词的歧义并返回 使用crf的上下文用sklearn_crfsuite实现。
- 通过将pkuseg提供的分段结果与开源词典CC-CEDICT相关联,
显示以下综合信息。
- 单词
- 词性
- 拼音
- 描述性拼音:应用汉语变调规则的地方
- 英语意思
- 传统等价物
算法(举例说明)
例如,输入:我quoten几代码(我写了几行代码)
第一步。使用pkuseg分段输入字符串。
- ->;[('25105;','r'),('a','v'),('u','u'),('20960;','m'),('a','q'),('20195;码','n'),('.','w')]
第二步。查找CC-CEDICT。每个标记,一个元组,由 单词,词性,发音候选,词义候选,繁体候选。
- ->;[('25105;,'r',['wo3',['/i/me/my/'],['25105;']),
('To','V',[ xIE3′],['/to to /'],[`'′]),
('u',['le5','liao3','liao4',[dal粒子..],'dal','le5','liao3','liao4'),
('几','米',['吉3','吉1',['/多少/.'],['吉','吉1'),
('',',',',',',',',',',','','')'BR/> (‘代码’、‘N’、‘DAI4 MA3’、['/code/']、[‘代碼’),
('.','W',['.],['',['.]]
- ->;[('25105;,'r',['wo3',['/i/me/my/'],['25105;']),
第三步。对于复音词,我们使用预先训练的crf模型来消除它们的歧义。
- ->;[(“我”、“R”、“WO3”、“I/ME/My/”、“我”),
('',','','xe3 ','/to ' /','' '),
('u','u','le5','/(模态粒子..','e'),
('几','M','JI3','多少/.','幾'),
('s','q','hang2',“/row/.”,'q'),
(“代码”、“N”、“DAI4 MA3”、“代码/”、“代碼”),
('.','W','.','.','.','','.')
- ->;[(“我”、“R”、“WO3”、“I/ME/My/”、“我”),
第四步。应用音调变化规则。
- ->;[(“我”,“r”,“wo3”,“wo2”,“i/me/my/”,“我”),
('','','','x3 ','xi3 ','/to ' /','' '),
('0','u','le5','le5','/(模态粒子..','e'),
('几'、'M'、'JI3'、'JI3'、'多少/.'、'幾'),
('0','q','hang2','hang2,'/row/.','q'),
(‘代码’、‘N’、‘DAI4 MA3’、‘DAI4 MA3’、‘/code/’、‘代30908;’),
('.','W','.','.','.','','.')
- ->;[(“我”,“r”,“wo3”,“wo2”,“i/me/my/”,“我”),
用法
>>> from g2pc import G2pC
>>> g2p = G2pC()
>>> g2p("一心一意")
# This returns a list of tuples, each of which consists of
# word, pos, pinyin, (tone changed) descriptive pinyin, English meaning, and equivanlent traditional character.
[[('一心一意',
'i',
'yi1 xin1 yi1 yi4',
'yi4 xin1 yi2 yi4',
"/concentrating one's thoughts and efforts/single-minded/bent on/intently/",
'一心一意')]
与其他库的尊重比较
>>> text1 = "我写了几行代码。" # pay attention to the 行, which should be read as 'hang2', not 'xing2'
>>> text2 = "来不了" # pay attention to the 了, which should be read as 'liao3', not 'le'
# python-pinyin
>>> pip install pypinyin
>>> from pypinyin import pinyin
>>> pinyin(text1)
[['wǒ'], ['xiě'], ['le'], ['jǐ'], ['xíng'], ['dài'], ['mǎ'], ['。']]
>>> pinyin(text2)
[['lái'], ['bù'], ['le']]
# xpinyin
>>> pip install xpinyin
>>> from xpinyin import Pinyin
>>> p = Pinyin()
>>> p.get_pinyin(text1, tone_marks="numbers")
'wo3-xie3-le5-ji1-xing2-dai4-ma3-。'
>>> p.get_pinyin(text2, tone_marks="numbers")
'lai2-bu4-le5'
更改日志
0.9.9.3 2019年7月10日
- 完善变调规则。
0.9.9.2 2019年7月10日
- 改进了
cedict.pkl
。
0.9.9.1 2019年7月9日
- 修正了找不到中文名字的错误。(见this)
0.9.6条。2019年7月7日
- 修正了无法转换字典中找不到的单词的错误。
- 重新武装
cedict.pkl
。 - 改进了crf模型。
- 增加变调规则。(见this)
0.9.4条。2019年7月4日
- 首次发布
参考文献
如果您使用我们的软件进行研究,请引用:
@misc{gp2C2019,
author = {Park, Kyubyong},
title = {g2pC},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/Kyubyong/g2pC}}
}