skip to content

Model Hubs & Embeddings

Pulling pretrained models from the Hugging Face Hub, running them with Transformers, and encoding text with Sentence Transformers or Transformers.js. Interviewers test practical sourcing skill.

on this pageshow

explore

questions

64 · 3 sections

In Hugging Face Datasets, what does load_dataset() return for a Hub repo or local files, and how do you map files to splits?

level: juniorimportance: must knowfreq 30%
basics
~20 s

load_dataset() returns a DatasetDict of splits, or one Arrow-backed Dataset when split= is given. It reads a Hub repo, a local folder, or a builder name such as "json" with data_files, whose {split: files} mapping names the splits.

open as a page

In Hugging Face Transformers v5, what does a minimal Trainer fine-tuning run need, and which TrainingArguments do you actually set?

level: juniorimportance: must knowfreq 38%
basics
~10 s

Trainer needs a model, a TrainingArguments object, a tokenized train_dataset and, in Transformers v5, the tokenizer passed as processing_class. First set output_dir, per_device_train_batch_size, gradient_accumulation_steps, eval_strategy, save_strategy, bf16 and report_to.

open as a page

What is the difference between Hugging Face Inference Providers and Inference Endpoints, and how is each one billed?

level: juniorimportance: must knowfreq 14%
basics
~20 s

Inference Providers route a Hub model id to a partner that already serves it, billed per request at that provider's own rate. Inference Endpoints deploy the model on a dedicated instance you choose, billed for the time it runs.

open as a page

In Hugging Face Transformers, what does a single pipeline('sentiment-analysis') call assemble for you, and what should you pin before production?

level: juniorimportance: must knowfreq 38%
basics
~20 s

pipeline('sentiment-analysis') maps the alias to text-classification, loads that task's default checkpoint through AutoModelForSequenceClassification with its tokenizer, and turns logits into label and score dicts. Pin model= and revision= so production stops depending on library defaults.

open as a page

In Hugging Face Transformers, what does calling a tokenizer on a batch with padding, truncation and return_tensors='pt' return, and what is the attention_mask for?

level: juniorimportance: must knowfreq 40%
basics
~10 s

It returns a BatchEncoding: a dict-like object whose input_ids and attention_mask are tensors of one shape. The attention_mask is 1 on real tokens and 0 on padding, so the model ignores the padded positions.

open as a page

In Sentence Transformers, when do you call CrossEncoder.predict and when CrossEncoder.rank, and what does each one return?

level: juniorimportance: must knowfreq 24%
basics
~20 s

CrossEncoder.predict scores a list of (query, passage) pairs and returns one score per pair in input order. CrossEncoder.rank takes one query and a list of documents and returns them sorted by score as corpus_id/score dicts.

open as a page

In Sentence Transformers, what do model.encode() and model.similarity() return when you embed a list of sentences and compare them?

level: juniorimportance: must knowfreq 40%
basics
~20 s

encode() returns a numpy array with one row per input (a 1-D vector for a single string); similarity() returns a torch tensor of shape [len(a), len(b)] scoring every pair, with cosine as the default function.

open as a page

A Sentence Transformers semantic-search prototype re-encodes the whole corpus on every query; how do you restructure it around util.semantic_search?

level: middleimportance: must knowfreq 25%
basics
~10 s

Encode the corpus once with encode_document() and cache the result; per request encode only the query with encode_query(), call util.semantic_search(query_emb, corpus_emb, top_k=k), and map each hit's corpus_id back to your texts.

open as a page

When picking a Sentence Transformers checkpoint for English passage retrieval from the MTEB leaderboard, which scores and model-card facts should decide it?

level: middleimportance: must knowfreq 30%
basics
~20 s

Read the Retrieval task average for the languages you serve rather than the overall MTEB mean, then the card: parameter count, embedding dimension, max_seq_length against your chunk length, and whether the score assumed query or passage prompts.

open as a page

In Sentence Transformers, which loss fits unlabelled (question, answer) pairs, pairs with a similarity score, and (anchor, positive, negative) triplets, and why?

level: middleimportance: must knowfreq 28%
basics
~10 s

Unlabelled pairs: MultipleNegativesRankingLoss, which uses the rest of the batch as negatives. Scored pairs: CoSENTLoss or CosineSimilarityLoss. Triplets: MultipleNegativesRankingLoss again, with the negative added, or TripletLoss with a tuned margin.

open as a page

In Transformers.js, what happens when a web page runs `await pipeline('sentiment-analysis')`, and why is that first call slow?

level: juniorimportance: must knowfreq 12%
basics
~20 s

pipeline() is an async factory: it resolves the task, picks a model (the task default if none is given), downloads config, tokenizer and ONNX weights from the Hub, and builds a callable pipeline. That download makes the first call slow.

open as a page

An in-browser Transformers.js text-classification widget freezes the page for 40 seconds on first load; how do you move the pipeline into a Web Worker?

level: middleimportance: must knowfreq 10%
basics
~20 s

Create the pipeline inside a module Web Worker, keep the pipeline() promise in a lazy singleton, and forward progress events and results to the page with postMessage. Session creation and inference then run off the main thread.

open as a page

A Transformers.js demo created with device 'webgpu' throws on some teammates' browsers — what fails, and how should the page choose its device instead?

level: seniorimportance: must knowfreq 11%
basics
~20 s

On a browser without WebGPU, Transformers.js throws Unsupported device: "webgpu", listing the devices it does support; an explicit 'webgpu' never falls back by itself. Detect WebGPU yourself (navigator.gpu plus a non-null adapter), pass 'webgpu' or 'wasm', and retry on 'wasm' if loading fails.

open as a page

In Transformers.js, which ONNX Runtime package executes the model in a browser versus in Node, and which device does each use by default?

level: juniorimportance: should knowfreq 9%
basics
~20 s

Transformers.js hands the ONNX graph to onnxruntime-web in a browser or worker and to onnxruntime-node under Node. With no device option the browser runs on 'wasm' (WebAssembly on the CPU) and Node on 'cpu' (native code).

open as a page

In Transformers.js, why does the same pipeline download a much larger ONNX file after you switch its device from 'wasm' to 'webgpu'?

level: middleimportance: should knowfreq 7%
basics
~10 s

With no dtype option (and none in the model's config), Transformers.js picks it from the device: q8 on 'wasm', fp32 on every other device including 'webgpu'. Switching device silently swaps onnx/model_quantized.onnx for onnx/model.onnx.

open as a page