栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

POINTER运行记录

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

POINTER运行记录

最近在运行EMNLP 2020 paper: "POINTER: Constrained Progressive Text Generation via Insertion-based Generative Pre-training"的代碼:GitHub - dreasysnail/POINTERContribute to dreasysnail/POINTER development by creating an account on GitHub.https://github.com/dreasysnail/POINTER

遇到的问题记录如下(持续更新):

  • nltk.download('stopwords')失敗:

从Github上下载stopwords.zip,并解压放到目录下。
Github地址为 https://github.com/nltk/nltk_data/tree/gh-pages/packages/corpora
至于放到哪个目录,在执行nltk.downloads(‘stopwords’)最后会给你这样的提示:(由於是之後記錄的,所以使用了他人的圖片)

我最後是放在/opt/conda/envs/SpareNet/nltk_data/corpora/stopwords.zip下,注意不存在的文件夾需要自己創建。

  • ubuntu繁体字转换简体字:

ctrl+shift+c+f

  • BertTokenizer使用详解:

一文学会Pytorch版本BERT使用_ccbrid的博客-CSDN博客前言:coder们最常用的Pytorch版本的BERT应该就是这一份了吧https://github.com/huggingface/pytorch-pretrained-BERT这份是刚出BERT的时候出的,暂且叫它旧版我在学习使用旧版的时候粗略的记过一些笔记:https://blog.csdn.net/ccbrid/article/details/88732857随着BER...https://blog.csdn.net/ccbrid/article/details/104355299/

  • 在BertTokenizer中加入自己的词汇:

在training.py 第247行中加入以下代码:

    with open('iu_vocab.json','r') as f:
        tokens_list = json.load(f)['vocab']
  

    tokenizer = BertTokenizer.from_pretrained(args.bert_model, do_lower_case=args.do_lower_case)

    tokenizer.add_tokens(tokens_list)

然后在载入模型时,training.py第282行加入以下代码:

    else:
        model = BertForMaskedLM.from_pretrained(args.bert_model)
        model.resize_token_embeddings(args.len_tokens)
  • 遇到问题:decoder的vocab_size没有resize:

在modeling_bert.py第299行加入以下代码:

    def _tie_or_clone_weights(self, first_module, second_module):
        """ Tie or clone module weights depending of weither we are using Torchscript or not
        """
        # Update bias size if has attribuate bias
        if hasattr(self, "cls"):
            self.cls.predictions.bias.data = torch.nn.functional.pad(
                self.cls.predictions.bias.data,
                (0, self.config.vocab_size - self.cls.predictions.bias.shape[0]),
                "constant",
                0,
            )
        if self.config.torchscript:
            first_module.weight = nn.Parameter(second_module.weight.clone())
        else:
            first_module.weight = second_module.weight

参考了github上大佬的issues:https://github.com/huggingface/transformers/issues/2480https://github.com/huggingface/transformers/issues/2480

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/275273.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号