Back to Ailearning

加载自定义包(添加: 中间件)

src/py3.x/tensorflow2.x/test.ipynb

2.01.4 KB
Original Source
python
import sys
# 加载自定义包(添加: 中间件)
sys.path.append("src/py3.x/tensorflow2.x")
from text_Emotion import *
python
outfile = "/opt/data/开源词向量/gensim_word2vec_60/Word60.model"
# 加载词向量
Word2VecModel = loadMyWord2Vec(outfile)
python
embeddings_matrix = load_embeding()
python
print('--: ', embeddings_matrix)
python
import re
import os
import keras
import random
import gensim
import numpy as np
import pandas as pd
from keras import Model
from keras.models import load_model
from keras.layers import Dropout, Dense, Flatten, Bidirectional, Embedding, GRU, Input
from keras.optimizers import Adam
# 该目录下的 config.py文件, 数据文件是: poetry.txt
from config import Config

python
model = EmotionModel(Config)
python
df = pd.read_excel("src/py3.x/tensorflow2.x/EmotionData.xlsx", header=0, error_bad_lines=False, encoding="utf_8_sig")
df.head(10)
python
y = df["label"].tolist()
y[:10]
python

def func(line, ngrams=[]):
    # 加入我们的组合词,保证分词的准确性
        
    if ngrams != []:
        for word in ngrams:
            jieba.add_word("".join(word.lower()))
    # # 将文本 ['1, 2, 3', '1, 2, .., n'] 分解为: [[1, 2, 3], [1, 2, .., n]]
    words = [word for word in jieba.cut(str(line).lower(), cut_all=False)]
    # print(">>> ", train)
    return " ".join(words)
x = df["comment"].apply(lambda line: func(line))