Code Monkey home page Code Monkey logo

Comments (3)

timoschick avatar timoschick commented on September 3, 2024 1

Hi, the input length is automatically reduced to 512 tokens while leaving the tokens corresponding to labels intact. However, you need to define an appropriate PVP that always includes the maximum number of masks required for any label. Could you share your custom PVP?

Edit: As this was missing from the documentation, I've updated the README file accordingly: https://github.com/timoschick/pet#pet-with-multiple-masks

from pet.

timoschick avatar timoschick commented on September 3, 2024 1

Does this mean that i have to multiply self.mask by the number of maximum mask tokens?

Yes, exactly. I don't know how exactly "西大須" gets tokenized, but if it consists of two tokens, you'll have to insert two masks (as you did in your bottom example).

from pet.

darwinharianto avatar darwinharianto commented on September 3, 2024

Thanks for the clarification. This is my PVP class. There is only 1 self.mask when returning get_parts.

class TestPVP(PVP):
    VERBALIZER = {
        "1": ["他"],
        "2": ["西大須"]
    }
    
    
    def get_parts(self, example: InputExample) -> FilledPattern:

        text_a = self.shortenable(example.text_a)
        text_b = self.shortenable(example.text_b)

        if self.pattern_id == 0:
            return [self.mask, ':', text_a, text_b], []
        elif self.pattern_id == 1:
            return [self.mask, '問題は:', text_a, text_b], []
        elif self.pattern_id == 2:
            return [text_a, '(', self.mask, ')', text_b], []
        elif self.pattern_id == 3:
            return [text_a, text_b, '(', self.mask, ')'], []
        elif self.pattern_id == 4:
            return ['[ クラス分類:', self.mask, ']', text_a, text_b], []
        elif self.pattern_id == 5:
            return [self.mask, '-', text_a, text_b], []
        else:
            raise ValueError("No pattern implemented for id {}".format(self.pattern_id))

    def verbalize(self, label) -> List[str]:
        return TestPVP.VERBALIZER[label]

Thanks for the documentation.

respectively, your get_parts() method should always return a sequence that contains exactly 3 mask tokens
Does this mean that i have to multiply self.mask by the number of maximum mask tokens?

class TestPVP(PVP):
    VERBALIZER = {
        "1": ["他"],
        "2": ["西大須"]
    }
    
    
    def get_parts(self, example: InputExample) -> FilledPattern:

        text_a = self.shortenable(example.text_a)
        text_b = self.shortenable(example.text_b)

        if self.pattern_id == 0:
            return [self.mask, self.mask, ':', text_a, text_b], []
        elif self.pattern_id == 1:
            return [self.mask, self.mask, '問題は:', text_a, text_b], []
        elif self.pattern_id == 2:
            return [text_a, '(', self.mask, self.mask, ')', text_b], []
        elif self.pattern_id == 3:
            return [text_a, text_b, '(', self.mask, self.mask, ')'], []
        elif self.pattern_id == 4:
            return ['[ クラス分類:', self.mask, self.mask, ']', text_a, text_b], []
        elif self.pattern_id == 5:
            return [self.mask, self.mask, '-', text_a, text_b], []
        else:
            raise ValueError("No pattern implemented for id {}".format(self.pattern_id))

    def verbalize(self, label) -> List[str]:
        return TestPVP.VERBALIZER[label]

from pet.

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.