【问题标题】:Get the size of vocabulary in tensorflow tokenizer获取 tensorflow 分词器中的词汇量
【发布时间】:2021-05-10 15:01:47
【问题描述】:

标记化后如何获取(未知数据集的)词汇表的大小?

那是代码:

f = open("parallel2200Tab.txt","r")
pairs = [line.strip().split("\t") for line in  f]
f.close()
docs = tf.data.Dataset.from_tensor_slices(pairs)

tokenizer = text.WhitespaceTokenizer()
tokenized_docs = docs.map(lambda x: tokenizer.tokenize(x))

我需要知道词汇量的大小来训练我的模型。

【问题讨论】:

    标签: tensorflow nlp tokenize


    【解决方案1】:

    标记化的文档应该可以像字典一样访问,所以试试吧:

    print(len(tokenized_docs))
    

    或者在半途而废的调试模式下打印出来:

    i = 0
    for k,v in tokenized_docs.items():
        print("word: "+k)
        print("numeric token: "+v)
        i++
        print("token count: "+i)
    

    【讨论】:

    • 差不多了。这个“print(len(tokenized_docs))”给出了句子的数量。我想要文档中不同单词的数量
    猜你喜欢
    • 2017-04-01
    • 2020-08-19
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 2018-12-12
    • 2019-04-30
    • 2016-10-07
    • 2021-10-18
    相关资源
    最近更新 更多