fasttaxt:数据预处理和生成词向量

本文介绍了如何运用FastText对数据进行预处理,包括符号处理、分词步骤,并详细讲解了利用FastText生成词向量的参数设置。参考官方文档以获取更多关于FastText未监督学习教程的信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据预处理:

1,符号处理:

def go_split(s,min_len):
    # 拼接正则表达式
    symbol = ',;。!、?!'
    symbol = "[" + symbol + "]+"
    # 一次性分割字符串
    result = re.split(symbol, s)
return [x for x in result if len(x)>min_len]

def is_dup(s,min_len):
    result = go_split(s,min_len)
return len(result) !=len(set(result))

def is_neg_symbol(uchar):
    neg_symbol=['!', '0', ';', '?', '、', '。', ',']
return uchar in neg_symbol

2,分词

#encoding=utf-8
#author linxinzhu
import jieba
import sys
reload(sys)
sys.setdefaultencoding('utf8')
f = open('3.txt','r')
outf = open('4.txt','w')
for line in f:


    line = line.decode("utf-8").encode("utf-8")
    seg_text = jieba.cut(line.replace("\t"," ").replace("\n"," ")) # 去掉\t \n然后用jieba分词切分
    outline = " ".join(seg_text) # combined into a outline
   # outline = outline.encode("utf-8") + "\t__label__" + e + "\n" # add label
    outf.write(out
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值