Code Monkey home page Code Monkey logo

Comments (2)

uakarsh avatar uakarsh commented on July 20, 2024 1

Here is how you can do it:

  1. Write a dataset class, which reads an image address and the labels associated with it (like for sequence labeling, in which we need to predict what is the class for each text, we would have a label of (seq_len, 1), since each would have a single class)
  2. Now, extract the features using the create_features function
  3. And from the dataset object, return the 5 parameters (1. resized_scaled_img, 2.x_features, 3.y_featuers, 4. input_ids, 5l. labels)
  4. Use a collate function in PyTorch for handling multiple inputs from a single dataset and then pass it as follows:
  • Use ResNetFeatureExtractor, to get the image feature of the resized_scaled)img
  • Use DocFormerEmbedding, to get the extracted features of x_features, y_features
  • Use LanguageFeatureExtractor, to get the features of the tokenized words
  1. Having obtained these things, pass it through the DocFormerEncoder
  2. And then, attach a linear layer according to your task requirement
  3. Take the loss and backward propagate it

Hope this helps

We would shortly include these things in a smaller boilerplate, so that code becomes more clear and more concise, but I hope this helps.

from docformer.

gnanaravindhan avatar gnanaravindhan commented on July 20, 2024

Here is how you can do it:

  1. Write a dataset class, which reads an image address and the labels associated with it (like for sequence labeling, in which we need to predict what is the class for each text, we would have a label of (seq_len, 1), since each would have a single class)
  2. Now, extract the features using the create_features function
  3. And from the dataset object, return the 5 parameters (1. resized_scaled_img, 2.x_features, 3.y_featuers, 4. input_ids, 5l. labels)
  4. Use a collate function in PyTorch for handling multiple inputs from a single dataset and then pass it as follows:
  • Use ResNetFeatureExtractor, to get the image feature of the resized_scaled)img
  • Use DocFormerEmbedding, to get the extracted features of x_features, y_features
  • Use LanguageFeatureExtractor, to get the features of the tokenized words
  1. Having obtained these things, pass it through the DocFormerEncoder
  2. And then, attach a linear layer according to your task requirement
  3. Take the loss and backward propagate it

Hope this helps

We would shortly include these things in a smaller boilerplate, so that code becomes more clear and more concise, but I hope this helps.

@uakarsh Thanks for detailed step by step explanation, i'll have a go at it.

from docformer.

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.