语料库corpus

本文汇总了多种汉语语料库资源,包括现代汉语、古代汉语、汉英双语、口语、新闻分类等,覆盖了从学术研究到工业应用的广泛需求。文中提供了各大高校、研究机构及在线平台的语料库链接,是语言学、自然语言处理等领域研究者的宝贵资料。
语料库在线 http://www.cncorpus.org/
现代汉语语料库 http://ccl.pku.edu.cn/corpus.asp?item=1
古代汉语语料库 http://ccl.pku.edu.cn/corpus.asp?item=2
汉英双语语料库 http://ccl.pku.edu.cn/corpus.asp?item=3
HSK动态作文语料库 http://202.112.195.192:8060/hsk/login.asp
北京口语语料查询系统 http://www.blcu.edu.cn/yys/6_beijing/6_beijing_chaxun.asp
现代汉语平衡语料库 http://rocling.iis.sinica.edu.tw/new/20corpus.htm
LIVAC共時語料庫 http://www.livac.org/index.php
兰开斯特汉语语料库 http://ling.cass.cn/dangdai/LCMC/LCMC.htm
洛杉矶加州大学汉语语料库 http://www.lancs.ac.uk/fass/projects/corpus/UCLA/
中文新闻分类语料库 http://www.nlpir.org/?action-viewnews-itemid-145
NLPIR 500万条twitter内容语料库 http://www.nlpir.org/?action-viewnews-itemid-263
NLPIR微博博主语料库100万条 http://www.nlpir.org/?action-viewnews-itemid-232
現代漢語語料庫詞頻統計 http://elearning.ling.sinica.edu.tw/CWordfreq.html
欢迎关注新浪微博【对外汉语北京】
中文句結構樹資料庫 http://turing.iis.sinica.edu.tw/treesearch/
搜狗文本分类语料库 http://www.sogou.com/labs/dl/c.html
哈工大信息检索研究室对外共享语料库 http://ir.hit.edu.cn/demo/ltp/Sharing_Plan.htm
传媒大学文本语料库 http://ling.cuc.edu.cn/RawPub/
词语研究资源库 对外汉语北京 http://ling.cuc.edu.cn/newword/web/index.asp
BFSU CQPweb多语言在线语料库检索平台 http://www.iresearch.ac.cn/paper/detail.php?ItemID=6358
英汉双语平行语料库 http://www.luweixmu.com/ec-corpus/
babel 汉英平行语料库 http://icl.pku.edu.cn/icl_groups/parallel/default.htm
中国法律法规汉英平行语料库(大陆) http://corpus.zscas.edu.cn/lawcorpus1/index.asp
国家语言资源监测与研究中心 http://www.clr.org.cn/
British National Corpus http://www.natcorp.ox.ac.uk/
欢迎关注新浪微博【对外汉语北京】

转载于:https://www.cnblogs.com/StevenL/p/6818583.html

### 使用 PyTorch 构建语料库和词表 在自然语言处理 (NLP) 中,构建语料库和词表是许多任务的基础步骤。以下是通过 Python 和 PyTorch 实现这一过程的代码示例。 #### 加载数据并创建语料库 首先定义一个函数来读取文本文件并将它们转换为单词列表: ```python import re from collections import Counter import torch def load_corpus(file_path): """加载语料库""" with open(file_path, 'r', encoding='utf-8') as f: text = f.read().lower() # 去除非字母字符并分割成单词 words = re.findall(r'\b\w+\b', text) return words ``` #### 创建词表 接下来,基于加载的语料库生成一个映射单词到索引的词表: ```python class Vocab: def __init__(self, corpus, min_freq=1): self.min_freq = min_freq counter = Counter(corpus) self.idx_to_token = ['<pad>', '<unk>'] + [ token for token, freq in counter.items() if freq >= min_freq and not token.isdigit()] self.token_to_idx = {token: idx for idx, token in enumerate(self.idx_to_token)} def __len__(self): return len(self.idx_to_token) def convert_tokens_to_ids(self, tokens): return [self[token] for token in tokens] def __getitem__(self, token): return self.token_to_idx.get(token, self.token_to_idx['<unk>']) ``` #### 将文本转化为张量 为了使模型能够接受输入,需将文本序列转换为数值化的张量形式: ```python def tokenize_and_convert(corpus, vocab): indices = [] for word in corpus: index = vocab[word] indices.append(index) return torch.tensor(indices, dtype=torch.long) ``` #### 完整流程演示 假设有一个简单的文本文件 `example.txt`,可以按照以下方式运行整个流程: ```python if __name__ == "__main__": file_path = './example.txt' corpus = load_corpus(file_path) # 载入语料库 vocab = Vocab(corpus, min_freq=2) # 创建词表 print(f"Vocabulary size: {len(vocab)}") # 输出词汇大小 tensor_data = tokenize_and_convert(corpus, vocab) # 文本转张量 print(tensor_data[:10]) # 打印前十个词语对应的索引 ``` 此方法涵盖了从原始文本到适合神经网络使用的张量表示的过程[^3]。 ### 注意事项 对于更复杂的 NLP 应用场景,可能还需要考虑停用词移除、分词工具的选择等问题[^4]。例如中文分词可借助第三方库如 `pkuseg` 来完成[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值