codewithkyrian/transformers
A Laravel-friendly transformers package for turning models, arrays, and API responses into consistent, reusable output. Define transformer classes, map fields, nest relations, and format data cleanly for JSON APIs, with minimal boilerplate and flexible customization.
The Question Answering (QA) pipeline enables models to extract or generate answers to questions based on a given text context. This functionality is particularly useful for digging through documents to find answers or even generating answers without direct context in some advanced models.
question-answeringXenova/distilbert-base-uncased-distilled-squadQuestion Answering models are versatile tools with numerous applications, such as:
To use the Question Answering pipeline, you'll need to provide both a question and a context. The context is the text or document where the model will look for the answer. Here's an example:
$question = "Who is known as the father of computers?";
$context = "The history of computing is longer than the history of computing hardware and modern computing technology
and includes the history of methods intended for pen and paper or for chalk and slate, with or without the aid of tables.
Charles Babbage is often regarded as one of the fathers of computing because of his contributions to the basic design of
the computer through his analytical engine.";
$pipeline = pipeline('question-answering', 'Xenova/distilbert-base-cased-distilled-squad');
$result = $pipeline($question, $context);
When running the question-answering pipeline, you can the following arguments:
question (string)The question you'd like to ask. It's the first argument so there's no need to include it as a named argument.
context (string)This provides the text that contains the potential answer. It's always going to be the second argument so there's no need to include it as a named argument.
topK[Optional] Specifies how many potential answers to return. By default, it's set to 1, meaning the model will return the highest-scoring answer. Increasing this value allows you to see more possible answers along with their confidence scores.
$result = $pipeline($question, $context, topK: 2);
The output of the pipeline is typically an array containing the best answer found within the context, along with its
confidence score. . When topK is set to a value greater than 1, the output will include multiple answers, sorted by
their confidence scores.
E.g. For a single best answer (topK = 1), the output might look like this:
["answer" => "Charles Babbage", "score" => 0.99892232198209]
And for topK = 2
[
["answer" => "Charles Babbage", "score" => 0.99892232198209],
["answer" => "Charles", "score" => 0.00048067486262722]
]
How can I help you explore Laravel packages today?