NLP 英文資料預處理

2021-09-28 16:17:47 字數 1734 閱讀 8593

目錄

理論(文字特徵提取)

● 詞袋模型

● tf-idf模型

● 高階詞向量模型

部分**

gensim_doc2bow+lda

gensim_tfidf+lda

結果對比

主流:谷歌的word2vec演算法,它是乙個基於神經網路的實現,使用cbow(continuous bags of words)和skip-gram兩種結構學習單詞的分布式向量表示。也可基於gensim庫實現。

# create dictionary

id2word = corpora.dictionary(data_lemmatized)

# create corpus

texts = data_lemmatized

# term document frequency

corpus = [id2word.doc2bow(text) for text in texts]

print()

#構建主題模型

#依然基於gensim

lda_model = gensim.models.ldamodel.ldamodel(corpus=corpus,

id2word=id2word,

num_topics=2,

random_state=100,

update_every=1,

chunksize=100,

passes=10,

alpha='auto',

per_word_topics=true)

#檢視lda模型中的主題

# print the keyword in the 10 topics

pprint(lda_model.print_topics())

doc_lda = lda_model[corpus]

import gensim.********** as api

from gensim.models import tfidfmodel

from gensim.corpora import dictionary

dct = dictionary(data_lemmatized) # fit dictionary

corpus = [dct.doc2bow(line) for line in data_lemmatized] # convert corpus to bow format

model = tfidfmodel(corpus) # fit model

#構建主題模型

#依然基於gensim

lda_model = gensim.models.ldamodel.ldamodel(corpus=vector,

id2word=dct,

num_topics=2,

random_state=100,

update_every=1,

chunksize=100,

passes=10,

alpha='auto',

per_word_topics=true)

#檢視lda模型中的主題

# print the keyword in the 10 topics

pprint(lda_model.print_topics())

doc_lda = lda_model[corpus]

主題數=2

nlp 中文資料預處理

資料載入 預設csv格式 import pandas as pd datas pd.read csv test.csv header 0,index col 0 dataframe n datas data.to numpy ndarray 轉成numpy更好處理 個人喜好 去除空行def dele...

語言模型之英文資料預處理

在做語言模型的時候需要對文字做一些預處理,將文字分成一行一句的形式,並標上開始符和結束符。1.句子切分 可以按照句號,問號,感嘆號,進行切分。然後從未到頭掃瞄一遍,將不是以大寫字母開頭的拼接到上一句上 對於類似於s.r這類的人名無法處理 text re.sub sss text text re.su...

小語種nlp文字預處理 資料清洗

開始繼續完成大資料實驗室招新題 roman urdu小語種為例 link 本練習賽所用資料,是名為 roman urdu dataset 的公開資料集。這些資料,均為文字資料。原始資料的文字,對應三類情感標籤 positive,negative,netural。本練習賽,移除了標籤為netural的...