比方說,我有三句話:兩字相鄰句子的
hello world
hello python
today is tuesday
如果我生成每個二元語法它會產生的字符串是這樣的:
[('hello', 'world')]
[('this', 'is'), ('is', 'python')]
[('today', 'is'), ('is', 'tuesday')]
是否有連續兩個句子的雙字母組的句子和雙字母組之間的差異?例如,hello world. hello python
是兩個連續的句子。對於這兩個連續的句子,bigrams看起來像我的輸出嗎?
產生它的代碼:
from itertools import tee, izip
def bigrams(iterable):
a, b = tee(iterable)
next(b, None)
return izip(a, b)
with open("hello.txt", 'r') as f:
for line in f:
words = line.strip().split()
bi = bigrams(words)
print list(bi)
請重寫你的問題,使它是一致的。除此之外,如果您提供什麼是文本結構,以及期望的句子分隔符是什麼,那麼您將有更好的機會獲得答案 – jsbueno
您是否擁有生成元組列表的代碼?或者任何代碼? – jedwards
我認爲術語bigrams超載,據我所知這意味着任何兩個相鄰字符的組合? 與字符串「你好」,作爲「他」,「el」,「ll」和「lo」的bigrams。請在您的上下文中說明雙精度的定義。 – kraenhansen