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 pageshowhide
explore
- Hugging Face33 questions
- Repos, Revisions & Access5 questions
- Pipelines & Hub Tasks5 questions
- Tokenizers & Chat Templates6 questions
- Datasets Library6 questions
- Inference Providers & Endpoints6 questions
- Fine-tuning and Trainer5 questions
- Sentence Transformers21 questions
- Encoding & Similarity APIs5 questions
- CrossEncoder Class & Rerankers5 questions
- Fine-tuning & Loss Functions6 questions
- Checkpoint Choice & Backends5 questions
- Transformers.js10 questions
- In-Browser Pipelines5 questions
- Devices & Execution Backends5 questions
questions
64 · 3 sectionsIn Hugging Face Datasets, what does load_dataset() return for a Hub repo or local files, and how do you map files to splits?
basics
~20 sload_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.
In Hugging Face Transformers v5, what does a minimal Trainer fine-tuning run need, and which TrainingArguments do you actually set?
basics
~10 sTrainer 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.
What is the difference between Hugging Face Inference Providers and Inference Endpoints, and how is each one billed?
basics
~20 sInference 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.
In Hugging Face Transformers, what does a single pipeline('sentiment-analysis') call assemble for you, and what should you pin before production?
basics
~20 spipeline('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.
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?
basics
~10 sIt 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.
In Sentence Transformers, when do you call CrossEncoder.predict and when CrossEncoder.rank, and what does each one return?
basics
~20 sCrossEncoder.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.
In Sentence Transformers, what do model.encode() and model.similarity() return when you embed a list of sentences and compare them?
basics
~20 sencode() 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.
A Sentence Transformers semantic-search prototype re-encodes the whole corpus on every query; how do you restructure it around util.semantic_search?
basics
~10 sEncode 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.
When picking a Sentence Transformers checkpoint for English passage retrieval from the MTEB leaderboard, which scores and model-card facts should decide it?
basics
~20 sRead 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.
In Sentence Transformers, which loss fits unlabelled (question, answer) pairs, pairs with a similarity score, and (anchor, positive, negative) triplets, and why?
basics
~10 sUnlabelled 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.
In Transformers.js, what happens when a web page runs `await pipeline('sentiment-analysis')`, and why is that first call slow?
basics
~20 spipeline() 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.
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?
basics
~20 sCreate 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.
A Transformers.js demo created with device 'webgpu' throws on some teammates' browsers — what fails, and how should the page choose its device instead?
basics
~20 sOn 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.
In Transformers.js, which ONNX Runtime package executes the model in a browser versus in Node, and which device does each use by default?
basics
~20 sTransformers.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).
In Transformers.js, why does the same pipeline download a much larger ONNX file after you switch its device from 'wasm' to 'webgpu'?
basics
~10 sWith 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.