Class: HfInference

Constructors

constructor

new HfInference(apiKey?, defaultOptions?)

Parameters

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

Defined in

HfInference.ts:513

Properties

apiKey

Private Readonly apiKey: string

Defined in

HfInference.ts:510


defaultOptions

Private Readonly defaultOptions: Options

Defined in

HfInference.ts:511

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:737


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:718


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:688


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:709


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:521


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:757


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:805


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:777


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:555


request

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

Type parameters

Name
T

Parameters

Name Type
args Args & { data?: ArrayBuffer | Blob }
options? Options & { binary?: boolean ; blob?: boolean ; includeCredentials?: boolean }

Returns

Promise<T>

Defined in

HfInference.ts:837


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:543


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:573


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:596


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:609


textToImage

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

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<Blob>

Defined in

HfInference.ts:825


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:621


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:647


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:659