相关疑难解决方法(0)

将字符串拆分为具有多个单词边界分隔符的单词

我认为我想做的是一项相当普遍的任务,但我在网上找不到任何参考.我有带标点符号的文字,我想要一个单词列表.

"Hey, you - what are you doing here!?"
Run Code Online (Sandbox Code Playgroud)

应该

['hey', 'you', 'what', 'are', 'you', 'doing', 'here']
Run Code Online (Sandbox Code Playgroud)

但是Python str.split()只能使用一个参数,所以在用空格分割之后,我所有的单词都带有标点符号.有任何想法吗?

python string split

631
推荐指数
12
解决办法
63万
查看次数

NLTK:语料级别的蓝色vs句级BLEU得分

我在python中导入了nltk来计算Ubuntu上的BLEU分数.我理解句子级BLEU分数是如何工作的,但我不明白语料库级BLEU分数是如何工作的.

以下是我的语料级BLEU分数代码:

import nltk

hypothesis = ['This', 'is', 'cat'] 
reference = ['This', 'is', 'a', 'cat']
BLEUscore = nltk.translate.bleu_score.corpus_bleu([reference], [hypothesis], weights = [1])
print(BLEUscore)
Run Code Online (Sandbox Code Playgroud)

出于某种原因,上述代码的bleu得分为0.我期待一个语料库级别的BLEU评分至少为0.5.

这是我的句子级BLEU分数的代码

import nltk

hypothesis = ['This', 'is', 'cat'] 
reference = ['This', 'is', 'a', 'cat']
BLEUscore = nltk.translate.bleu_score.sentence_bleu([reference], hypothesis, weights = [1])
print(BLEUscore)
Run Code Online (Sandbox Code Playgroud)

考虑到简短惩罚和缺失的单词"a",这里的句子级BLEU分数是0.71.但是,我不明白语料库级别的BLEU分数是如何工作的.

任何帮助,将不胜感激.

python nlp machine-learning nltk bleu

11
推荐指数
2
解决办法
9182
查看次数

标签 统计

python ×2

bleu ×1

machine-learning ×1

nlp ×1

nltk ×1

split ×1

string ×1