Class: HfInference

Constructors

constructor

new HfInference(apiKey?, defaultOptions?)

Parameters

Name Type Default value
apiKey string ""
defaultOptions Options {}

Defined in

HfInference.ts:507

Properties

apiKey

Private Readonly apiKey: string

Defined in

HfInference.ts:504


defaultOptions

Private Readonly defaultOptions: Options

Defined in

HfInference.ts:505

Methods

audioClassification

audioClassification(args, options?): Promise<AudioClassificationReturn>

This task reads some audio input and outputs the likelihood of classes. Recommended model: superb/hubert-large-superb-er

Parameters

Name Type
args AudioClassificationArgs
options? Options

Returns

Promise<AudioClassificationReturn>

Defined in

HfInference.ts:617


automaticSpeechRecognition

automaticSpeechRecognition(args, options?): Promise<AutomaticSpeechRecognitionReturn>

This task reads some audio input and outputs the said words within the audio files. Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self

Parameters

Name Type
args AutomaticSpeechRecognitionArgs
options? Options

Returns

Promise<AutomaticSpeechRecognitionReturn>

Defined in

HfInference.ts:603


conversational

conversational(args, options?): Promise<ConversationalReturn>

This task corresponds to any chatbot like structure. Models tend to have shorter max_length, so please check with caution when using a given model if you need long range dependency or not. Recommended model: microsoft/DialoGPT-large.

Parameters

Name Type
args ConversationalArgs
options? Options

Returns

Promise<ConversationalReturn>

Defined in

HfInference.ts:588


featureExtraction

featureExtraction(args, options?): Promise<FeatureExtractionReturn>

This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.

Parameters

Name Type
args FeatureExtractionArgs
options? Options

Returns

Promise<FeatureExtractionReturn>

Defined in

HfInference.ts:595


fillMask

fillMask(args, options?): Promise<FillMaskReturn>

Tries to fill in a hole with a missing word (token to be precise). That’s the base task for BERT models.

Parameters

Name Type
args FillMaskArgs
options? Options

Returns

Promise<FillMaskReturn>

Defined in

HfInference.ts:515


imageClassification

imageClassification(args, options?): Promise<ImageClassificationReturn>

This task reads some image input and outputs the likelihood of classes. Recommended model: google/vit-base-patch16-224

Parameters

Name Type
args ImageClassificationArgs
options? Options

Returns

Promise<ImageClassificationReturn>

Defined in

HfInference.ts:631


imageSegmentation

imageSegmentation(args, options?): Promise<ImageSegmentationReturn>

This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects. Recommended model: facebook/detr-resnet-50-panoptic

Parameters

Name Type
args ImageSegmentationArgs
options? Options

Returns

Promise<ImageSegmentationReturn>

Defined in

HfInference.ts:656


objectDetection

objectDetection(args, options?): Promise<ObjectDetectionReturn>

This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects. Recommended model: facebook/detr-resnet-50

Parameters

Name Type
args ObjectDetectionArgs
options? Options

Returns

Promise<ObjectDetectionReturn>

Defined in

HfInference.ts:645


questionAnswer

questionAnswer(args, options?): Promise<QuestionAnswerReturn>

Want to have a nice know-it-all bot that can answer any question?. Recommended model: deepset/roberta-base-squad2

Parameters

Name Type
args QuestionAnswerArgs
options? Options

Returns

Promise<QuestionAnswerReturn>

Defined in

HfInference.ts:529


request

request(args, options?): Promise<any>

Parameters

Name Type
args Args & { data?: any }
options? Options & { binary?: boolean ; blob?: boolean }

Returns

Promise<any>

Defined in

HfInference.ts:674


summarization

summarization(args, options?): Promise<SummarizationReturn>

This task is well known to summarize longer text into shorter text. Be careful, some models have a maximum length of input. That means that the summary cannot handle full books for instance. Be careful when choosing your model.

Parameters

Name Type
args SummarizationArgs
options? Options

Returns

Promise<SummarizationReturn>

Defined in

HfInference.ts:522


tableQuestionAnswer

tableQuestionAnswer(args, options?): Promise<TableQuestionAnswerReturn>

Don’t know SQL? Don’t want to dive into a large spreadsheet? Ask questions in plain english! Recommended model: google/tapas-base-finetuned-wtq.

Parameters

Name Type
args TableQuestionAnswerArgs
options? Options

Returns

Promise<TableQuestionAnswerReturn>

Defined in

HfInference.ts:536


textClassification

textClassification(args, options?): Promise<TextClassificationReturn>

Usually used for sentiment-analysis this will output the likelihood of classes of an input. Recommended model: distilbert-base-uncased-finetuned-sst-2-english

Parameters

Name Type
args TextClassificationArgs
options? Options

Returns

Promise<TextClassificationReturn>

Defined in

HfInference.ts:546


textGeneration

textGeneration(args, options?): Promise<TextGenerationReturn>

Use to continue text from a prompt. This is a very generic task. Recommended model: gpt2 (it’s a simple model, but fun to play with).

Parameters

Name Type
args TextGenerationArgs
options? Options

Returns

Promise<TextGenerationReturn>

Defined in

HfInference.ts:553


textToImage

textToImage(args, options?): Promise<ArrayBuffer>

This task reads some text input and outputs an image. Recommended model: stabilityai/stable-diffusion-2

Parameters

Name Type
args TextToImageArgs
options? Options

Returns

Promise<ArrayBuffer>

Defined in

HfInference.ts:667


tokenClassification

tokenClassification(args, options?): Promise<TokenClassificationReturn>

Usually used for sentence parsing, either grammatical, or Named Entity Recognition (NER) to understand keywords contained within text. Recommended model: dbmdz/bert-large-cased-finetuned-conll03-english

Parameters

Name Type
args TokenClassificationArgs
options? Options

Returns

Promise<TokenClassificationReturn>

Defined in

HfInference.ts:560


translation

translation(args, options?): Promise<TranslationReturn>

This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en.

Parameters

Name Type
args TranslationArgs
options? Options

Returns

Promise<TranslationReturn>

Defined in

HfInference.ts:570


zeroShotClassification

zeroShotClassification(args, options?): Promise<ZeroShotClassificationReturn>

This task is super useful to try out classification with zero code, you simply pass a sentence/paragraph and the possible labels for that sentence, and you get a result. Recommended model: facebook/bart-large-mnli.

Parameters

Name Type
args ZeroShotClassificationArgs
options? Options

Returns

Promise<ZeroShotClassificationReturn>

Defined in

HfInference.ts:577


toArray

Static Private toArray(obj): any[]

Parameters

Name Type
obj any

Returns

any[]

Defined in

HfInference.ts:732