NLP | 论文摘要文本分类

基于论文摘要的文本分类与关键词抽取挑战赛
​​​​​​2023 iFLYTEK A.I.开发者大赛-讯飞开放平台

环境需求:Anaconda-JupyterNotebook,或者百度AIStudio

赛题解析:

【文本二分类任务】根据论文摘要等信息理解,将论文划分为0-1两类别之一。

【文本关键词识别任务】从给定的论文中识别和提取出与论文内容相关的关键词。

数据样例:title、author、Abstract、Keywords、[label] 0-1

一键运行的时候先把csv删了(是运行结果)

安装nltk 【更换镜像源避免安装出错】

python 复制代码
!pip install nltk -i http://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
python 复制代码
# 导入pandas用于读取表格数据
import pandas as pd

# 导入BOW(词袋模型)
from sklearn.feature_extraction.text import CountVectorizer
#可以替换为TfidfVectorizer(TF-IDF(词频-逆文档频率))
#注意上下文要同时修改,亲测后者效果更佳

# 导入LogisticRegression回归模型
from sklearn.linear_model import LogisticRegression

# 过滤警告消息
from warnings import simplefilter
from sklearn.exceptions import ConvergenceWarning
simplefilter("ignore", category=ConvergenceWarning)


# 读取数据集
train = pd.read_csv('/home/aistudio/data/data231041/train.csv')
train['title'] = train['title'].fillna('')
train['abstract'] = train['abstract'].fillna('')

test = pd.read_csv('/home/aistudio/data/data231041/testB.csv')
test['title'] = test['title'].fillna('')
test['abstract'] = test['abstract'].fillna('')


# 提取文本特征,生成训练集与测试集
train['text'] = train['title'].fillna('') + ' ' +  train['author'].fillna('') + ' ' + train['abstract'].fillna('')+ ' ' + train['Keywords'].fillna('')
test['text'] = test['title'].fillna('') + ' ' +  test['author'].fillna('') + ' ' + test['abstract'].fillna('')

vector = CountVectorizer().fit(train['text'])
train_vector = vector.transform(train['text'])
test_vector = vector.transform(test['text'])


# 引入模型
model = LogisticRegression()

# 开始训练,这里可以考虑修改默认的batch_size与epoch来取得更好的效果
model.fit(train_vector, train['label'])

# 利用模型对测试集label标签进行预测
test['label'] = model.predict(test_vector)
test['Keywords'] = test['title'].fillna('')
test[['uuid','Keywords','label']].to_csv('submit_task1.csv', index=None)

ndarray.finall()方法:填充空值

pandas数据处理常用命令_ndarray fillna_hellosc01的博客-CSDN博客

Basedline的方法:BOW词袋提取特征-LR逻辑回归-进行预测

改进方法:TF-IDF,SVM,epoches

python 复制代码
# TfidfVectorizer(TF-IDF(词频-逆文档频率))
from sklearn.feature_extraction.text import TfidfVectorizer
python 复制代码
# 导入支持向量机分类器
from sklearn.svm import SVC

#创建SVM训练模型 
model = SVC(kernel='linear', C=1)

# 利用模型对测试集label标签进行预测
test['label'] = model.predict(test_vector)
test['Keywords'] = test['title'].fillna('')
test[['uuid','Keywords','label']].to_csv('submit_task2.csv', index=None)

by ライト

相关推荐
来酱何人15 小时前
低资源NLP数据处理:少样本/零样本场景下数据增强与迁移学习结合方案
人工智能·深度学习·分类·nlp·bert
风雨中的小七18 小时前
解密prompt系列62. Agent Memory一览 - MATTS & CFGM & MIRIX
llm·nlp
闲人编程1 天前
深入浅出Transformer:使用Hugging Face库快速上手NLP
python·深度学习·自然语言处理·nlp·transformer·hugging face·codecapsule
takashi_void2 天前
如何在本地部署大语言模型(Windows,Mac,Linux)三系统教程
linux·人工智能·windows·macos·语言模型·nlp
来酱何人3 天前
机器翻译数据处理核心技术:从语料到模型的质量管控链路
人工智能·分类·nlp·bert·机器翻译
渣渣盟5 天前
解密NLP:从入门到精通
人工智能·python·nlp
只是懒得想了5 天前
使用 Gensim 进行主题建模(LDA)与词向量训练(Word2Vec)的完整指南
人工智能·自然语言处理·nlp·word2vec·gensim
AI人工智能+6 天前
发票识别技术:结合OCR与AI技术,实现纸质票据高效数字化,推动企业智能化转型
人工智能·nlp·ocr·发票识别
东方芷兰7 天前
LLM 笔记 —— 07 Tokenizers(BPE、WordPeice、SentencePiece、Unigram)
人工智能·笔记·深度学习·神经网络·语言模型·自然语言处理·nlp
flying_13147 天前
自然语言处理分享系列-词语和短语的分布式表示及其组合性(一)
自然语言处理·nlp·word2vec·softmax·skip-gram·hierarchical·分层softmax