def _read_words(filename): with tf.gfile.GFile(filename, "r") as f: if Py3: return f.read().replace("\n", "<eos>").split() else: return f.read().decode("utf-8").replace("\n", "<eos>").split() def _build_vocab(filename): data = _read_words(filename) print("data:",data) counter = collections.Counter(data) print("counter:",counter) # temp_pairs = sorted(counter.items(), key=lambda x: print((-x[1], x[0]))) # print(" temp_pairs:", temp_pairs) count_pairs = sorted(counter.items(), key=lambda x: (x[1], x[0])) print(" count_pairs:", count_pairs) words, _ = list(zip(*count_pairs)) print("words:", words) word_to_id = dict(zip(words, range(len(words)))) print(" word_to_id:", word_to_id) return word_to_id def setUp(self): self._string_data = "\n".join( [" hello there i am", " rain as day", " want some cheesy puffs wu"]) def testPtbRawData(self): tmpdir = tf.test.get_temp_dir() for suffix in "train", "valid", "test": filename = os.path.join(tmpdir, "ptb.%s.txt" % suffix) with tf.gfile.GFile(filename, "w") as fh: fh.write(self._string_data) # Smoke test output = reader.ptb_raw_data(tmpdir) 打印结果 data Tensor("PTBProducer_1/Reshape:0", shape=(3, ?), dtype=int32) ..data: ['hello', 'there', 'i', 'am<eos>', 'rain', 'as', 'day<eos>', 'want', 'some', 'cheesy', 'puffs', 'wu'] counter: Counter({'there': 1, 'wu': 1, 'as': 1, 'hello': 1, 'puffs': 1, 'am<eos>': 1, 'cheesy': 1, 'day<eos>': 1, 'some': 1, 'i': 1, 'rain': 1, 'want': 1}) count_pairs: [('am<eos>', 1), ('as', 1), ('cheesy', 1), ('day<eos>', 1), ('hello', 1), ('i', 1), ('puffs', 1), ('rain', 1), ('some', 1), ('there', 1), ('want', 1), ('wu', 1)] words: ('am<eos>', 'as', 'cheesy', 'day<eos>', 'hello', 'i', 'puffs', 'rain', 'some', 'there', 'want', 'wu') word_to_id: {'want': 10, 'there': 9, 'day<eos>': 3, 'wu': 11, 'hello': 4, 'puffs': 6, 'am<eos>': 0, 'cheesy': 2, 'rain': 7, 'some': 8, 'i': 5, 'as': 1}
相关推荐
星际译王、金牌词典 词库的压缩工具,把.dict文件压缩为.dict.dz
主要介绍了Python sorted对list和dict排序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
dict的词典转换成DZ格式,dict的词典转换成DZ格式
Sentiment_dict.zip
JS拼音转汉字的包,非常实用 1. 体积足够小,适合web环境,常见汉字字典文件仅26kb,完整汉字也只有122kb,应该说是互联网上最小的; 2. 支持多种输出格式,如带声调、不带声调、拼音首字母; 3. 支持多音字:如果不...
下面是几个例子: >> > from skiplist import SortedSet , SortedDict>> > d = SortedDict ({ 'elma' : 1 , 'armut' : 2 , 'kel' : 3 , 'mahmut' : 4 })>> > dSortedDict ({ 'armut' : 2 , 'elma' : 1 , 'kel' : 3 ...
配套博客:https://blog.csdn.net/qq_41739364/article/details/96767359
行政区区域位置及对应编码
dict字典文件,单词本,xml格式,关键字为单词
盘古分词字典dict.dct 以及bin下面dict文件夹下面的txt文件 包含 ChsDoubleName1.txt ChsDoubleName2.txt ChsSingleName.txt Stopword.txt Synonym.txt Wildcard.txt
3.4DICT智慧园区解决方案培训材料.zip
Dict 字典词汇表
jcseg-1.9.4-src-jar-dict.zip
62.Python之访问dict共3页.pdf.zip
65.Python之遍历dict共2页.pdf.zip
Python之使用dict和set共8页.pdf.zip
本案例针对RML2016.10a_dict数据集并利用VT-CNN2 Mod-Rec Network卷积神经网络对信号实现自动调制方式识别,使用卷积神经网络在图像处理问题中的位移不变性特点,来解决调制识别的问题,使用网络结构来学习匹配...
63.Python中dict的特点共2页.pdf.zip