# NLP-Tasks **Repository Path**: changlehung/NLP-Tasks ## Basic Information - **Project Name**: NLP-Tasks - **Description**: Tasks of NLP Course in Nov.2020 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2020-12-03 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Tasks of NLP Course in Autumn 2020 * [Naive Bayes & Text Classification](#Naive-Bayes-and-Text-Classification) * [LSTM for Sequence Labeling](#LSTM-for-Sequence-Labeling) * [Word2vec & Embedding](#Word2vec-Embedding) ## Naive Bayes and Text Classification ### Introduction to dataset 实验中使用的数据集是`苏轼`和`杜甫`的诗词,具体内容查看[https://github.com/Chang-LeHung/NLP-Tasks/tree/main/datasets/poems](https://github.com/Chang-LeHung/NLP-Tasks/tree/main/datasets/poems)中的 `dufu.json` 和 `sushi.json` 这里面还有一些其他的数据,可以用来做多分类,比如分类多个诗人的诗词,分类写人、写景的诗词等等,实验为了方便 和朴素贝叶斯进行对比,只进行了二分类。 实验中使用的数据集已经提取出来了,是`final set.npz`中的数据,具体加载和提取数据方式如下 ```python import numpy as np datasets = np.load("final set.npz") datasets.allow_pickle = True my_mapping = datasets["use_word2idx"] dataset = datasets["dataset"] dufu = dataset.item()["dufu"] sushi = dataset.item()["sushi"] word2idx = datasets["word2idx"] idx2word = datasets["idx2word"] ``` `my_mapping` 可以将一个数据数组变成相应的诗词,分别作为诗词的开始和结束。 ```python my_mapping[dataset.item()["sushi"]] array([['', '', '', ..., '去', '。', ''], ['', '', '', ..., '思', '。', ''], ['', '', '', ..., '工', '。', ''], ..., ['', '', '', ..., '谗', '。', ''], ['', '', '', ..., '夸', '。', ''], ['', '', '', ..., '章', '。', '']], dtype='前面都是作为填充使用,因为诗词长度不一致所以需要填充 array(['', '雨', '细', '方', '梅', '夏', ',', '风', '高', '已', '麦', '秋', '。', '应', '怜', '百', '花', '尽', ',', '绿', '叶', '暗', '红', '榴', '。', ''], dtype='