Git Product home page Git Product logo

Comments (5)

yzhangcs avatar yzhangcs commented on August 25, 2024

Hi, thank you for reporting this potential issue. I will fix it soon later, or feel free to create a PR.

from parser.

attardi avatar attardi commented on August 25, 2024

I have a patch.
In method Parser.load(), it recreates the tokenizer:

    transform = state['transform']
    if args.feat == 'bert':
        tokenizer = SubwordField.tokenizer(args.bert)
        transform.FORM[1].tokenize = tokenizer.tokenize
    return cls(args, model, transform)

invoking this method in class SubwordField:

@classmethod
def tokenizer(cls, name):
    """                                                                                
    Create an instance of tokenizer from either path or name.                          
    :param name: path or name of tokenizer.                                            
    """

    from transformers import AutoTokenizer
    tokenizer = AutoTokenizer.from_pretrained(name)
    tokenizer.bos_token = tokenizer.bos_token or tokenizer.cls_token
tokenizer.eos_token = tokenizer.eos_token or tokenizer.sep_token
    return tokenizer

and biaffine-parser also uses it to create it, in class method build():

    elif args.feat == 'bert':
        tokenizer = SubwordField.tokenizer(args.bert)

You may also want too avoid to save the tokenize function, by doing this in Parser.save():

    if args.feat == 'bert':
        tokenize = self.transform.FORM[1].tokenize # save it                           
        self.transform.FORM[1].tokenize = None
    state = {'name': self.NAME,
             'args': args,
             'state_dict': state_dict,
             'pretrained': pretrained,
             'transform': self.transform}
    torch.save(state, path)
    if args.feat == 'bert':
        self.transform.FORM[1].tokenize = tokenize # restore                           

What do you think?

I cannot make a PR, since I have other changes in my code.

from parser.

yzhangcs avatar yzhangcs commented on August 25, 2024

@attardi That's might not be very elegant, I suppose tokenize to be a more general method, and directly moving the initialization of BertTokenizer inside SubwordField might not be a good choice.
I haven't figured out any solution to the above problem though.
BTW, with more parsers to be added, I think I'm increasingly losing the control of the field APIs. While torchtext is on the way to redesign their APIs to be more compatible with PyTorch and transformers and the new release can be available in October, I'm considering whether it is worth to replacing some of my impls with torchtext. Do you have any suggestions?

from parser.

yzhangcs avatar yzhangcs commented on August 25, 2024

@attardi As a temporary solution, I have re-uploaded the models trained with transformers 3.2.0.

from parser.

yzhangcs avatar yzhangcs commented on August 25, 2024

@attardi Done. The newly uploaded models are trained with transformers==3.2.0, and can be loaded with transformers==4.0.0.

from parser.

Related Issues (20)

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.