NLP文本处理

2019-07-16  本文已影响0人  在努力的Jie

分词 Segmentation

分词可以认为是已经解决的问题

分词工具 Segmentation Tools

Jieba分词 : https://github.com/fxsjy/jieba
SnowNLp  :  https://github.com/isnowfy/snownlp
LTP      :  http://www.ltp-cloud.com/
HanNLP    : https://github.com/hankcs/HanLP/

分词方法 Segmentation Method

1. 基于匹配规则的方法—Max Matching(最大匹配)

前项最大匹配(forward-max matching):从前向后扫描max_len的长度
后向最大匹配 (backward-max matchine):从后向前扫描max_len的长度
最大匹配的缺点:
PS:
1. 两种匹配方法结果90%会一样
2. 算法分为:贪心算法:选择当前最好解,不能看到全局最优解、DP算法:Global Optional
3. 这是贪心算法

2. 基于概率统计的方法—Language Model

(LM、HMM、CRF...)

Incorporate Semantic(考虑语义)

step1: 输入

<——生成所有可能的分割——>

step2: 选择其中最好的(by LM)

PS:1. 缺点: 复杂度很高,计算效率低
   2. 对于underflow(相乘结果小数点太多溢出问题)的解决办法 :“P——>logP”

3. 维特比算法(※)

合并step1和step2,解决计算效率低问题

动态规划问题,LM依赖Unigram

Steps:
数学公式表示维特比算法

斐波那契: f(n) = f(n-1) + f(n-2)

Spell Correction 拼写错误纠正

(搜索相关)

用户输入(input)
<—AI—>
用户输入(correction)

1.错别字,2.词义不合适
触发机制:1:不存在于词典库 2:LM,P值很低 or...

Progess

  1. 当前单词 —(edit distance)—> find all Candidates
  2. 过滤掉不存在词库里的词—> Candidates
  3. -(NoisyChannel)-> Answer corrected

计算编辑距离的方法

初始方法:

input ——> find min(edit distance) ——> return Candidates

复杂度高O(V),V:字典中的所有词

alternative way(优化):

文本表示

Word Repressentation 向量表示单词

Sentence Representation 向量表示句子

文本相似度

Sentence Similarity

Word2Vector词向量

Words Similarity

Comparing the Capacities

Learn Word Embeddings

Input(string) ——> 深度学习模型 ——> Distributed Representation

Essence of Word Embedding

Word2Vec 某种意义上理解成词的意思(Meaning)

训练词向量时,可以将训练结果放到二维空间,看二维空间中的词是否有一些分类的特点

From Word Embedding to Sentence Embedding

Inverted Index倒排表

Retrieval-based QA System

input ——> 与知识库相似度匹配 ——> 返回相似度最高的

优化—解决以上时间复杂度高的问题,核心思想“层次过滤思想”

input ——>过滤1 ——> 过滤2(多层过滤)——> 相似度匹配算法(cosin-similarity)——> return

时间复杂度:过滤器1 < 过滤器2 < cosin-similarity算法

上一篇 下一篇

猜你喜欢

热点阅读