示例#1
0
 def test_words2indices(self):
     v = Vocab('unk')
     words = ['i', 'like', 'pie']
     v.update(words)
     v = v.freeze()
     assert v.words2indices(words) == [1, 2, 3]
     assert v.words2indices(['i', 'said']) == [1, 0]
示例#2
0
 def test_words2indices(self):
     v = Vocab('unk')
     words = ['i', 'like', 'pie']
     v.update(words)
     v = v.freeze()
     assert v.words2indices(words) == [1, 2, 3]
     assert v.words2indices(['i', 'said']) == [1, 0]
示例#3
0
def test_eq(vocab):
    v = Vocab('unk')
    v.update('zero one two two three three three'.split())
    assert v == vocab
    v.add('zero', count=10)
    assert v == vocab  # equality doesn't depend on count
    v.add('four')
    assert v != vocab
示例#4
0
def test_eq(vocab):
    v = Vocab('unk')
    v.update('zero one two two three three three'.split())
    assert v == vocab
    v.add('zero', count=10)
    assert v == vocab  # equality doesn't depend on count
    v.add('four')
    assert v != vocab
示例#5
0
 def test_indices2words(self):
     v = Vocab(unk='unk')
     v.update(['i', 'like', 'pie'])
     words = v.indices2words([1, 2, 3, 0])
     assert words == ['i', 'like', 'pie', 'unk']
示例#6
0
def vocab():
    v = Vocab('unk')
    v.update('zero one two two three three three'.split())
    return v
示例#7
0
 def test_indices2words(self):
     v = Vocab(unk='unk')
     v.update(['i', 'like', 'pie'])
     words = v.indices2words([1, 2, 3, 0])
     assert words == ['i', 'like', 'pie', 'unk']
示例#8
0
def vocab():
    v = Vocab('unk')
    v.update('zero one two two three three three'.split())
    return v