吴裕雄--天生自然 pythonTensorFlow自然语言处理:Attention模型--测试
摘要:import sys import codecs import tensorflow as tf # 1.参数设置。 # 读取checkpoint的路径。9000表示是训练程序在第9000步保存的checkpoint。 CHECKPOINT_PATH = "F:\\temp\\attention_ckpt-9000" # 模型参数。必须与训练时的模型参数保持一致。 HIDDEN_SIZE =...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:Attention模型--训练
摘要:import tensorflow as tf # 1.参数设置。 # 假设输入数据已经转换成了单词编号的格式。 SRC_TRAIN_DATA = "F:\\TensorFlowGoogle\\201806-github\\TensorFlowGoogleCode\\Chapter09\\train.en" # 源语言输入文件。 TRG_TRAIN_DATA = "F:\\TensorFlowGo
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:Seq2Seq模型--测试
摘要:import sys import codecs import tensorflow as tf # 1.参数设置。 # 读取checkpoint的路径。9000表示是训练程序在第9000步保存的checkpoint。 CHECKPOINT_PATH = "F:\\temp\\seq2seq_ckpt-9000" # 模型参数。必须与训练时的模型参数保持一致。 HIDDEN_SIZE = 1024
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:Seq2Seq模型--训练
摘要:import tensorflow as tf # 1.参数设置。 # 假设输入数据已经用9.2.1小节中的方法转换成了单词编号的格式。 SRC_TRAIN_DATA = "F:\\TensorFlowGoogle\\201806-github\\TensorFlowGoogleCode\\Chapter09\\train.en" # 源语言输入文件。 TRG_TRAIN_DAT...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:PTB 语言模型
摘要:import numpy as np import tensorflow as tf # 1.设置参数。 TRAIN_DATA = "F:\TensorFlowGoogle\\201806-github\\TensorFlowGoogleCode\\Chapter09\\ptb.train" # 训练数据路径。 EVAL_DATA = "F:\TensorFlowGoogle...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:文本数据预处理--生成训练文件
摘要:import sys import codecs # 1. 参数设置 MODE = "PTB_TRAIN" # 将MODE设置为"PTB_TRAIN", "PTB_VALID", "PTB_TEST", "TRANSLATE_EN", "TRANSLATE_ZH"之一。 if MODE == "PTB_TRAIN": # PTB训练数据 RAW_DATA = "F:\\TensorFlowGoog
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:文本数据预处理--生成词汇表
摘要:import codecs import collections from operator import itemgetter # 1. 设置参数。 MODE = "PTB" # 将MODE设置为"PTB", "TRANSLATE_EN", "TRANSLATE_ZH"之一。 if MODE == "PTB": # PTB数据处理 RAW_DATA =...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:交叉熵损失函数
摘要:import tensorflow as tf # 1. sparse_softmax_cross_entropy_with_logits样例。 # 假设词汇表的大小为3, 语料包含两个单词"2 0" word_labels = tf.constant([2, 0]) # 假设模型对两个单词预测时,产生的logit分别是[2.0, -1.0, 3.0]和[1.0, 0.0, -0.5] pr...
阅读全文