Giter Site home page Giter Site logo

Comments (4)

guillaume-be avatar guillaume-be commented on June 9, 2024 1

@kj3moraes just had a look and I believe I have found the issue. The default maximum length for the text generation pipeline is 56 tokens (this includes the input prompt). Your input prompt most likely exceeds the 56 token default of the pipeline, and you have 2 solutions:

  • Change the max_length value of the TextGenerationConfig (you are currently using the default constructor). This is probably what you want to to.
  • pass a prompt that is shorter than the maximum length for text generation

Please let me know how this works. I will add a check to improve error handling when users provide inputs longer than the maximum length, thank you for raising this.

from rust-bert.

guillaume-be avatar guillaume-be commented on June 9, 2024

Hello @kj3moraes ,

Thank you for raising this. Could you please share a reproducible example (i.e. with a prompt and file you could share publicly) and turning the sampling off for the generation?

from rust-bert.

kj3moraes avatar kj3moraes commented on June 9, 2024

Thank you for raising this. Could you please share a reproducible example (i.e. with a prompt and file you could share publicly) and turning the sampling off for the generation?

This is the prompt that I use

Task: Extract summary and keywords from code

You are given a file containing code in a programming language. Your task is to reads the code from the file and generates a JSON output with two keys - 'summary' and 'keywords'.

1. 'summary': A string describing what the code is doing. This summary should capture the main purpose or functionality of the code in a concise manner.

2. 'keywords': A list of strings that includes relevant keywords related to the programming language used, the task being performed, or any significant terms present in the code.

The following is an example:

INPUT: 
from transformers import pipeline

image_to_text_model = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")

def convert_image_to_text(image_path: str) -> str :
    return image_to_text_model(image_path)

{
    "summary": "Function to caption the image at the specified path and returns it as a string",
    "keywords": ["python", "huggingface", "transformers", "image", "caption", "captioning"] 
}


INPUT:

An example file would be

use std::path::PathBuf;

pub fn path_to_string(path: &PathBuf) -> String {
    path.display().to_string()
}

pub fn path_to_filename_string(path: &PathBuf) -> Option<String> {
    Some(path.file_name()?.to_str()?.to_string())
}

from rust-bert.

kj3moraes avatar kj3moraes commented on June 9, 2024
* Change the `max_length` value of the  [`TextGenerationConfig`](https://github.com/guillaume-be/rust-bert/blob/9f2cd17e914dee9570e981c63a4021beb33250c2/src/pipelines/text_generation.rs#L59) (you are currently using the default constructor). This is probably what you want to to.

This worked thanks a lot. Returning a Result would be better for sure.

from rust-bert.

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.