Coder Social home page Coder Social logo

letianlee / bert-jittor Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 337 KB

A BERT model built with Jittor | 计图版 BERT 模型 | 计图 NLP 教程

License: Apache License 2.0

Python 22.51% Jupyter Notebook 77.49%
bert-model jittor language-model nlp nlp-tutorial text-classification bert jittor-tutorial

bert-jittor's People

Contributors

letianlee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

shiminhu

bert-jittor's Issues

'jittor_core.Var' object has no attribute 'trunc_normal_'

Hi 您好,
我现在正在尝试学习这个仓库的代码并完成清华今年机器学期课程的作业。
我使用的输入与您基本相同,但是在运行3. 加载模型及优化器(如下代码)的时候出现了错误

from bert_model import BertClassification, BertConfig
from jittor import optim

# 加载 BERT 模型
configuration = BertConfig()
model = BertClassification(configuration)
model.load_state_dict(jt.load("jittorhub://pretrained_bert.bin")) # 加载预训练的参数

# 加载 AdamW 优化器
optim = optim.AdamW(model.parameters(), lr=1e-5)

报错如下:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-120-5962eb72d2ee> in <module>
      4 # 加载 BERT 模型
      5 configuration = BertConfig()
----> 6 model = BertClassification(configuration)
      7 model.load_state_dict(jt.load("jittorhub://pretrained_bert.bin")) # 加载预训练的参数
      8 

~/.cache/jittor/notebook/hw4/bert_model.py in __init__(self, config)
    103         self.class_weight = config.class_weight
    104 
--> 105         self.bert = BertModel(config)
    106         self.dropout = nn.Dropout(config.hidden_dropout_prob)
    107         self.classifier = nn.Linear(config.hidden_size, config.num_labels)

~/.cache/jittor/notebook/hw4/bert_model.py in __init__(self, config, add_pooling_layer)
    148         self.pooler = BertPooler(config) if add_pooling_layer else None
    149 
--> 150         self.init_weights()
    151 
    152     def execute(

~/.cache/jittor/notebook/hw4/bert_model.py in init_weights(self)
     82     def init_weights(self):
     83         # Initialize weights
---> 84         self.apply(self._init_weights)
     85 
     86     def _init_weights(self, module):

/usr/local/lib/python3.8/dist-packages/jittor/__init__.py in apply(self, func)
    886     def apply(self, func):
    887         for m in self.modules():
--> 888             func(m)
    889 
    890     def load_parameters(self, params):

~/.cache/jittor/notebook/hw4/bert_model.py in _init_weights(self, module)
     91                 module.bias.zero_()
     92         elif isinstance(module, nn.Embedding):
---> 93             module.weight.trunc_normal_(mean=0.0, std=self.config.initializer_range)
     94         elif isinstance(module, nn.LayerNorm):
     95             module.bias.zero_()

AttributeError: 'jittor_core.Var' object has no attribute 'trunc_normal_'

我使用的是jittor/jittor-cuda-11-1作为docker环境中的jittor,版本为'1.2.2.59',请问这个报错跟版本有关吗?

十分感谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.