实验3 中文分词

必做题:

  1. 数据准备:academy_titles.txt为"考硕考博"板块的帖子标题,job_titles.txt为"招聘信息"板块的帖子标题,
  2. 使用jieba工具对academy_titles.txt进行分词,接着去除停用词,然后统计词频,最后绘制词云。同样的,也绘制job_titles.txt的词云。
  3. 将jieba替换为pkuseg工具,分别绘制academy_titles.txt和job_titles.txt的词云。要给出每一部分的代码。

效果图

代码

复制代码
import jieba
import re
from wordcloud import WordCloud
from collections import Counter
import matplotlib.pyplot as plt

# 读取academy_titles文件内容
with open('C:\\Users\\hp\\Desktop\\实验3\\academy_titles.txt', 'r', encoding='utf-8') as file:
    academy_titles = file.readlines()

# 读取job_titles文件内容
with open('C:\\Users\\hp\\Desktop\\实验3\\job_titles.txt', 'r', encoding='utf-8') as file:
    job_titles = file.readlines()

# 将招聘信息与学术信息分开
academy_titles = [title.strip() for title in academy_titles]
job_titles = [title.strip() for title in job_titles]

# 分词、去除停用词、统计词频(对academy_titles)
academy_words = []
for title in academy_titles:
    words = jieba.cut(title)
    filtered_words = [word for word in words if re.match(r'^[\u4e00-\u9fa5]+$', word)]
    academy_words.extend(filtered_words)

请自行补全代码,或者这周五晚上更新完整代码

相关推荐
MARS_AI_4 小时前
大语言模型驱动智能语音应答:技术演进与架构革新
人工智能·语言模型·自然语言处理·架构·信息与通信
0x2117 小时前
[论文阅读]LLMZip: Lossless Text Compression using Large Language Models
人工智能·语言模型·自然语言处理
Fairy要carry8 小时前
书生大模型实战营——1. 大语言模型原理与书生大模型提示词工程实践
人工智能·语言模型·自然语言处理
聚客AI10 小时前
搜索引擎vs向量数据库:LangChain混合检索架构实战解析
人工智能·pytorch·语言模型·自然语言处理·数据分析·gpt-3·文心一言
Jamence10 小时前
多模态大语言模型arxiv论文略读(156)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记
Shuai@11 小时前
VILA-M3: Enhancing Vision-Language Models with Medical Expert Knowledge
人工智能·语言模型·自然语言处理
夏末蝉未鸣0111 小时前
python transformers笔记(TrainingArguments类)
python·自然语言处理·transformer
Jamence1 天前
多模态大语言模型arxiv论文略读(151)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记
Brian Xia1 天前
Word2Vec模型详解:CBOW与Skip-gram
人工智能·自然语言处理·word2vec
九章云极AladdinEdu1 天前
冷冻电镜重构的GPU加速破局:从Relion到CryoSPARC的并行重构算法
人工智能·pytorch·深度学习·机器学习·自然语言处理·架构·gpu算力