Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c# example negative offset for Starts #177

Open
dbalikhin opened this issue Jul 19, 2023 · 0 comments
Open

c# example negative offset for Starts #177

dbalikhin opened this issue Jul 19, 2023 · 0 comments

Comments

@dbalikhin
Copy link

I'm trying to run a sample from readme file.

          // allocate space for ids and offsets
            int[] Ids = new int[128];
            int[] Starts = new int[128];
            int[] Ends = new int[128];

            // tokenize with loaded XLM Roberta tokenization and output ids and start and end offsets
            var outputCount = BlingFireUtils.TextToIdsWithOffsets(h, inBytes, inBytes.Length, Ids, Starts, Ends, Ids.Length, 0);

            Console.WriteLine(String.Format("return length: {0}", outputCount));
            if (outputCount >= 0)
            {
                Console.Write("tokens from offsets: [");
                for (int i = 0; i < outputCount; ++i)
                {
                    int startOffset = Starts[i];

Starts[0] will be -1 which will result to an exception while getting startOffset.

System.ArgumentOutOfRangeException: 'Non-negative number required. (Parameter 'offset')'

I can put a dummy fix - output results will be good.

if (Starts[0] == -1)
{
    Starts[0] = 0;
}

I'm not sure why I was getting negative offset.

System: Windows 11 x64 (getting the same error in WSL Ubuntu 22.04)
.NET 7.0 Console App

PS: I also have to add
Console.OutputEncoding = System.Text.Encoding.UTF8; to display UTF-8 properly in the console app, but it is explainable fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant