我一直在玩ElasticSearch以获得我的新项目.我已将默认分析器设置为使用ngram tokenfilter.这是我的elasticsearch.yml文件:
index:
analysis:
analyzer:
default_index:
tokenizer: standard
filter: [standard, stop, mynGram]
default_search:
tokenizer: standard
filter: [standard, stop]
filter:
mynGram:
type: nGram
min_gram: 1
max_gram: 10
Run Code Online (Sandbox Code Playgroud)
我创建了一个新索引并添加了以下文档:
$ curl -XPUT http://localhost:9200/test/newtype/3 -d '{"text": "one two three four five six"}'
{"ok":true,"_index":"test","_type":"newtype","_id":"3"}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用查询text:hree
或text:ive
任何其他部分术语进行搜索时,ElasticSearch不会返回此文档.它仅在我搜索确切的术语(如text:two
)时返回文档.
我也尝试更改配置文件,以便default_search也使用ngram令牌过滤器,但结果是相同的.我在这里做错了什么,如何纠正?
我只是想知道在考虑计算它们时的计算开销时n-gram(n> 3)(及其出现频率)的用途是什么.是否有任何应用程序,其中bigrams或trigrams是不够的?
如果是这样,那么n-gram提取的最新技术是什么?有什么建议?我知道以下内容:
甲马尔科夫链是由一组其可以以一定的概率转换到其他状态的状态的.
通过为每个状态创建一个节点,每个转换的关系,然后用适当的概率注释转换关系,可以很容易地在Neo4J中表示马尔可夫链.
但是,你能用Neo4J 模拟马尔可夫链吗?例如,可以强制Neo4J在某个状态下启动,然后根据概率转换到下一个状态和下一个状态吗?Neo4J可以打印出通过这个状态空间的路径吗?
也许通过一个简单的例子可以更容易理解.假设我想根据公司科技博客的文本制作一个2克的英语模型.我启动了一个执行以下操作的脚本:
count/totalcount
.这是转换概率.现在Neo4J图已经完成了,如何从我的2克英语模型中创建一个"句子"?输出可能是这样的:
在没有IST LAT WHEY CRATICT FROURE BIRS GROCID REPONSTURES的REPTAGIN是CRE的REGOACTIONA.
我正在寻找一个Python的接口来加载ARPA文件(回退语言模型),并利用它们来评估一些文字,如得到它的日志概率,困惑等.
我不需要在Python中生成ARPA文件,只是用它来进行查询.
有人推荐套餐吗?我已经看过kenlm和swig-srilm,但是第一个在Windows中很难设置,第二个似乎不再维护了.
对于我们构建的应用程序,我们使用简单的单词预测统计模型(如Google自动填充)来指导搜索.
它使用从大量相关文本文档中收集的一系列ngrams.通过考虑之前的N-1个单词,它使用Katz退避建议按概率降序排列的5个最可能的"下一个单词" .
我们希望将其扩展为预测短语(多个单词)而不是单个单词.但是,当我们预测短语时,我们宁愿不显示其前缀.
例如,考虑输入the cat
.
在这种情况下,我们希望做出预测the cat in the hat
,但the cat in
不是the cat in the
.
假设:
我们无法访问过去的搜索统计信息
我们没有标记的文本数据(例如,我们不知道词性)
制作这类多字预测的典型方法是什么?我们尝试过较长短语的乘法和加法加权,但我们的权重是任意的,适合我们的测试.
我正在努力解决一个棘手的问题并迷失方向.
这是我应该做的:
INPUT: file
OUTPUT: dictionary
Return a dictionary whose keys are all the words in the file (broken by
whitespace). The value for each word is a dictionary containing each word
that can follow the key and a count for the number of times it follows it.
You should lowercase everything.
Use strip and string.punctuation to strip the punctuation from the words.
Example:
>>> #example.txt is a file containing: "The cat chased the dog."
>>> with open('../data/example.txt') as f: …
Run Code Online (Sandbox Code Playgroud) 下面的代码将句子分成单独的标记,输出如下
"cloud" "computing" "is" "benefiting" " major" "manufacturing" "companies"
import en_core_web_sm
nlp = en_core_web_sm.load()
doc = nlp("Cloud computing is benefiting major manufacturing companies")
for token in doc:
print(token.text)
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想要的是,将“云计算”放在一起阅读,因为它在技术上是一个词。
基本上我正在寻找一个双克。Spacy 中是否有允许 Bi gram 或 Trigram 的任何功能?
我是python新手,需要帮助!我正在练习python NLTK文本分类.以下是我在http://www.laurentluce.com/posts/twitter-sentiment-analysis-using-python-and-nltk/上练习的代码示例
我试过这个
from nltk import bigrams
from nltk.probability import ELEProbDist, FreqDist
from nltk import NaiveBayesClassifier
from collections import defaultdict
train_samples = {}
with file ('positive.txt', 'rt') as f:
for line in f.readlines():
train_samples[line]='pos'
with file ('negative.txt', 'rt') as d:
for line in d.readlines():
train_samples[line]='neg'
f=open("test.txt", "r")
test_samples=f.readlines()
def bigramReturner(text):
tweetString = text.lower()
bigramFeatureVector = {}
for item in bigrams(tweetString.split()):
bigramFeatureVector.append(' '.join(item))
return bigramFeatureVector
def get_labeled_features(samples):
word_freqs = {}
for text, label in train_samples.items():
tokens = text.split()
for …
Run Code Online (Sandbox Code Playgroud) 我正在使用Python 3.5,使用Anaconda进行安装和管理.我想使用一些文本训练NGramModel(来自nltk).我的安装找不到模块nltk.model
这个问题有一些可能的答案(选择正确的答案,并解释如何做到这一点):
我是机器学习的新手,所以如果问题很简单,请放心.
我得到了一系列观察到的人物说,ABABBABBB .....(n个字符).我的目标是通过一些"学习"机制预测下一个角色.我的约束是观察到的字符(训练数据?)不是太多,即我说一个长度为6000的序列来学习基础模式
我很担心解决这个问题需要采取什么策略,我最初的赌注是:1)某种ngram模型?2)神经网络(LSTM等)?3)HMM
你能否指出解决这个问题的正确方法?
n-gram ×10
nltk ×4
python ×4
nlp ×3
python-3.x ×2
algorithm ×1
autocomplete ×1
counter ×1
cypher ×1
data-mining ×1
dictionary ×1
lstm ×1
neo4j ×1
phrases ×1
spacy ×1
text ×1
tokenize ×1