- 博客(21)
- 资源 (1)
- 收藏
- 关注
原创 crf
import reimport sklearn_crfsuitefrom sklearn_crfsuite import metricsfrom sklearn.externals import joblibdir = "//15基于CRF的中文命名实体识别模型实现//"class CorpusProcess(object): def __init__(self): """初始化""" self.train_corpus_path = dir+ "1980
2020-07-10 08:18:37 124
原创 bilstmcrf
import torchimport torch.nn as nnimport torch.optim as optimtorch.manual_seed(1)# some helper functionsdef argmax(vec): # return the argmax as a python int # 第1维度上最大值的下标 # input: tensor([[2,3,4]]) # output: 2 _, idx = torch.max(v
2020-07-10 08:10:55 185
原创 hmmpostagging
# 初始化词典tag2id, id2tag = {},{}word2id, id2word = {},{}#建立词典for line in open("traindata.txt"): items = line.split("/") word, tag = items[0],items[1].rstrip() if word not in word2id: word2id[word]=len(word2id) id2word[len(id2
2020-07-08 07:53:12 154
原创 hmmtrain
#!/usr/bin/env python3# coding: utf-8# open: hmm_train.py# Author: lhy<lhy_in_blcu@126.com,https://huangyong.github.io># Date: 18-3-26class HmmTrain: def __init__(self): self.line_index = -1 self.char_set = set() def in
2020-07-07 23:36:20 243
原创 hmmcut
#!/usr/bin/env python3# coding: utf-8# File: hmm_cut.py# Author: lhy<lhy_in_blcu@126.com,https://huangyong.github.io># Date: 18-3-26class HmmCut: def __init__(self): trans_path = './model/prob_trans.model' emit_path = './mod
2020-07-07 23:35:20 163
原创 attention6
# -- encoding:utf-8 --"""原始数据:[百, 柳, 报, 春, 兆] ----> [千,花,传,欢,乐]模型训练的时候,将原始数据进行转换:编码器输入: [百, 柳, 报, 春, 兆]解码器输入: [GO, 千,花,传,欢]解码器输出(实际值): [千,花,传,欢,乐]"""import tensorflow as tfdef build_interface(encoder_inputs, encoder_vocab_size,
2020-06-22 00:09:28 97
原创 seq2seq2
# -- encoding:utf-8 --"""原始数据:[小明, 吃, 苹果] ----> [xiao, ming, eats, apples]模型训练的时候,将原始数据进行转换:编码器输入: [小明, 吃, 苹果]解码器输入: 无解码器输出(实际值): [xiao, ming, eats, apples, EOS]"""import tensorflow as tfdef build_interface(encoder_inputs, enco
2020-06-19 08:10:29 94
原创 seq2seq1
# -- encoding:utf-8 --"""原始数据:[小明, 吃, 苹果] ----> [xiao, ming, eats, apples]模型训练的时候,将原始数据进行转换:编码器输入: [小明, 吃, 苹果]解码器输入: [GO, xiao, ming, eats, apples]解码器输出(实际值): [xiao, ming, eats, apples, EOS]"""import tensorflow as tfdef build_i
2020-06-19 08:09:47 183
原创 attention
# -- encoding:utf-8 --"""原始数据:[百, 柳, 报, 春, 兆] ----> [千,花,传,欢,乐]模型训练的时候,将原始数据进行转换:编码器输入: [百, 柳, 报, 春, 兆]解码器输入: [GO, 千,花,传,欢]解码器输出(实际值): [千,花,传,欢,乐]"""import tensorflow as tfdef build_interface(encoder_inputs, encoder_vocab_size,
2020-06-19 08:08:22 119 1
原创 w2v
# -- encoding:utf-8 --import osimport tensorflow as tfclass CBOWNetwork(object): def __init__(self, name="W2V", num_sampled=100, window=4, vocab_size=3365, embedding_size=128, is_mean=True, regularization=0.001, optimizer_name='
2020-06-18 07:38:30 292
原创 data_util
# -- encoding:utf-8 --import reimport osimport jiebaimport jsonimport numpy as npfrom collections import defaultdictre_han = re.compile(r"([\u4E00-\u9FD5]+)", re.U)PAD = "<PAD>" # 用于数据填充的UNKNOWN = "<UNKNOWN>" # 用于训练数据中不存在的数据def
2020-06-18 07:37:24 263
原创 train
# -- encoding:utf-8 --import osimport tensorflow as tffrom nets.w2vnet import CBOWNetwork, SkipGramNetworkfrom utils.data_utils import DataManager# parameters# =====================================# 模型训练数据参数tf.flags.DEFINE_string("data_path", ".
2020-06-18 07:34:24 324
原创 convert_data
# -- encoding:utf-8 --import osimport tensorflow as tffrom utils.data_utils import convert_sentence_to_wordsfrom utils.data_utils import build_dictionaryfrom utils.data_utils import convert_words_to_recordtf.app.flags.DEFINE_string("opt", "split",
2020-06-18 07:33:34 674
原创 剧本gen
"""项目:电视剧本生成。数据集:https://www.kaggle.com/wcukierski/the-simpsons-by-the-data提交时间:12月29日之前。 提交邮箱:yingjun@ibefeing.com"""from utils import helperimport numpy as npimport warningsfrom tensorflow.contrib import seq2seqimport tensorflow as tf# 数据读取...
2020-06-10 07:59:59 114
原创 英文情感
import numpy as npimport tensorflow as tffrom string import punctuationfrom collections import Counter# 介绍预览该项目,并介绍该项目网络结构!with open('../datas/sentiment/reviews.txt', 'r') as f: reviews = f.read()with open('../datas/sentiment/labels.txt', 'r'..
2020-06-10 07:58:48 208
原创 中文情感
import numpy as npimport matplotlib.pyplot as pltimport reimport jiebaimport osfrom sklearn.model_selection import train_test_splitfrom gensim.models import KeyedVectorsfrom keras.models import Sequentialfrom keras.layers import Dense, GRU, Embed..
2020-06-10 07:58:07 91
原创 Word2vec
# Embedding Skip-gramimport timeimport numpy as npimport tensorflow as tffrom utils import utilsfrom urllib.request import urlretrievefrom os.path import isfile, isdirfrom tqdm import tqdmimport zipfilefrom collections import Counterimport ran..
2020-06-10 07:57:08 75
原创 双向rnn英小短文
import osimport numpy as npimport tensorflow as tfdef load_data(file_path): """ 加载原始数据 :param file_path: :return: """ with open(file_path, 'r') as reader: data = reader.readlines() return datadef create_lookup_ta..
2020-06-09 00:40:14 95
原创 rnnapi
import tensorflow as tf"""tf.nn.rnn_cell # 定义rnn 细胞核相关的信息的tf.nn.rnn_cell_impl # 定义rnn细胞核具体是如何实现的tf.nn.dynamic_rnn() # 单向动态rnn。tf.nn.bidirectional_dynamic_rnn() # 双向动态rnntf.nn.static_rnn() # 单向静态rnntf.nn.static_bidirectional_rnn()..
2020-06-09 00:39:37 95
原创 charrnn
"""单词字符级别预测RNN"""import timefrom collections import namedtupleimport numpy as npimport tensorflow as tfimport oswith open('../datas/anna.txt', 'r') as f: text = f.read()vocab = sorted(set(text)) # 取文本中唯一的字符,共83个。vocab_to_int = {c: i f.
2020-06-09 00:38:38 159
原创 MobileNetOps
MobileNetOps.pyimport tensorflow as tf“”"实现Mobile_Net_V3的各个模块。“”"weight_decay = 1e-3def hswish(x, name=‘hswish’):return tf.multiply(x, tf.nn.relu6(x+3) / 6, name=name)def batch_norm(x, momentum=0.99, epsilon=1e-5, train=True, name=‘bn’):return tf.
2020-06-09 00:31:31 89
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人