huggingface / node-question-answering

Fast and production-ready question answering in Node.js
Apache License 2.0
464 stars 55 forks source link

How to test this library? #7

Closed balavenkatesh3322 closed 4 years ago

balavenkatesh3322 commented 4 years ago

How can I run this code to test this project?

import { QAClient } from "question-answering";

const text = `
  Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season.
  The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.
  As this was the 50th Super Bowl, the league emphasized the "golden anniversary" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as "Super Bowl L"), so that the logo could prominently feature the Arabic numerals 50.
`;

const question = "Who won the Super Bowl?";

const qaClient = await QAClient.fromOptions();
const answer = await qaClient.predict(question, text);

console.log(answer); // { text: 'Denver Broncos', score: 0.3 }

Do you have a sample js file to test this library?

Pierrci commented 4 years ago

Hi @balavenkatesh3322, a "sample js file" as you say wouldn't be enough, since you also need to download the model following the steps described in the readme:

Just pay attention to the first line of the code, if you're using plain vanilla JS (no Typescript or Babel), you should replace import { QAClient } from "question-answering"; by const { QAClient } = require("question-answering"); (I just updated the readme accordingly).

balavenkatesh3322 commented 4 years ago

Hi @Pierrci , Thanks for your explanation and an updated readme file.

As you said I created file and I got below error while running this command node myfile.js

internal/modules/cjs/loader.js:807
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: /home/bala/Documents/aibots/pdf project/node_modules/tokenizers/bin-package/index.node: undefined symbol: _ZN2v82V818GlobalizeReferenceEPNS_8internal7IsolateEPm
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/bala/Documents/aibots/pdf project/node_modules/tokenizers/bindings/native.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)

I have attached screenshot for your reference. busy-bas-b6x28 - CodeSandbox

Pierrci commented 4 years ago

Can you try replacing the line in error (line 3) with the following:

const { QAClient } = require("question-answering");

It seems that although you're running vanilla js, you used some typescript code to import QAClient.