Giter VIP home page Giter VIP logo

Comments (2)

mmaaz60 avatar mmaaz60 commented on August 10, 2024 1

Hi @Pumpkin123709,

Thank you for your interest in our work. You can use the function below to find token_positives.

def find_word_indices(caption, word):
    """
    Finds the start and end token indices of the first occurrence of a word in a caption.

    Parameters:
    - caption (str): The caption in which to search for the word.
    - word (str): The word to search for.

    Returns:
    - tuple: A tuple containing the start and end token indices of the word. If the word is not found, returns (-1, -1).
    """
    # Convert the caption and word to lowercase to make the search case-insensitive.
    caption_lower = caption.lower()
    word_lower = word.lower()

    # Find the start index of the word in the caption.
    start_idx = caption_lower.find(word_lower)

    # If the word is not found, check for its plural form by adding an 's' at the end.
    if start_idx == -1:
        new_word = word_lower.split('-')[0] + 's'
        start_idx = caption_lower.find(new_word)
        if start_idx == -1:
            return -1, -1, new_word
        else:
            return start_idx, start_idx + len(new_word), new_word

    # If the word is not found, return (-1, -1).
    if start_idx == -1:
        return -1, -1, word

    # Find the end index of the word in the caption.
    end_idx = start_idx + len(word)

    return (start_idx, end_idx, word)
start_idx, end_idx, word = find_word_indices(caption, word)
token_positives = [start_idx, end_idx]

I hope it will be helpful. Thank you and Good Luck!

from groundinglmm.

Pumpkin123709 avatar Pumpkin123709 commented on August 10, 2024

@mmaaz60 thanks!

from groundinglmm.

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.