国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

經(jīng)典的把一篇英文文章轉(zhuǎn)成word2id形式的dict的一段python程序

2019-11-06 08:26:20
字體:
供稿:網(wǎng)友
import collectionsimport tensorflow as tfdef _read_Words(filename): with tf.gfile.GFile(filename, "r") as f: return f.read().decode("utf-8").replace("/n", "<eos>").split()def _build_vocab(filename): data = _read_words(filename) counter = collections.Counter(data) count_pairs = sorted(counter.items(), key=lambda x: (-x[1], x[0])) words, _ = list(zip(*count_pairs)) word_to_id = dict(zip(words, range(len(words)))) return word_to_id

摘自https://github.com/tensorflow/models/blob/master/tutorials/rnn/ptb/reader.py


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 双辽市| 巴中市| 宽城| 海城市| 福鼎市| 玉环县| 太仓市| 临清市| 浦县| 陇西县| 科技| 文山县| 金堂县| 平利县| 柏乡县| 浪卡子县| 大埔县| 岗巴县| 镇巴县| 陆良县| 嘉祥县| 静乐县| 丰城市| 右玉县| 建平县| 衡阳县| 客服| 三河市| 牟定县| 潮安县| 麻城市| 天台县| 贵德县| 绍兴市| 同心县| 浏阳市| 贡觉县| 隆林| 新民市| 当涂县| 建湖县|