Objective & prerequisites
Encode meaning-related text and compare it with a transparent keyword baseline. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.
python3 lab.py
python3 -m unittest discover -s tests -vUnderstand the concept
An embedding maps text into a learned vector space. Here a pinned all-MiniLM-L6-v2 ONNX model encodes short English text into 384 dimensions. Attention-mask mean pooling combines token vectors and L2 normalization makes their length one. Cosine similarity compares direction, not factual truth or probability of relevance. The keyword baseline computes normalized overlap of token sets and cannot infer paraphrases without shared words. The local encoder uses explicit model files and CPU inference; it does not call a hosted API. Inputs longer than 256 wordpieces are refused so evidence is not silently truncated. For longer documents, design chunks with stable document IDs, offsets, version and neighboring context before indexing.
Worked example
The supplied run encoded eight passages and seven queries with the pinned model. Q1 asks how long exercise files remain obtainable; D1 says practice downloads last fourteen days after enrolment. Semantic top result is D1, while keyword top result is D6. The saved vector file includes model revision, dimensions and source hashes. New text requires encode.py with the actual model; fixture_rank only accepts known fixture query IDs and refuses stale source hashes. A brute-force in-memory cosine index is sufficient here; no vector database is implemented or needed for eight passages.
from lab import load,fixture_rank,keyword_rank
q=load("queries.json")[0]
assert fixture_rank("Q1")[0]["id"]=="D1"
assert keyword_rank(q["text"],load("corpus.json"))[0]["id"]=="D6"Try it yourself
Run the dependency-free replay and compare Q1 rankings. Optionally follow README to create a virtual environment, install the recorded semantic dependencies and explicitly download the pinned public model. Then run encode.py with a new short paraphrase. Do not describe replaying Q1 as encoding new text. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.
Worked solution
fixture_rank("Q1")[0] is D1. keyword_rank for Q1 puts D6 first in this frozen corpus. Actual inference is invoked only with an explicit local --model-dir. fetch_model.py downloads about 91 MB of public files and verifies fixed hashes; model weights are not bundled into the website or small ZIP. The model card declares Apache-2.0; retain provenance and review terms for later uses. Similarity differences on this tiny authored set do not demonstrate universal superiority.
Knowledge check
Is a cosine score of 0.8 an 80% probability that an answer is true?
Check and explain
No. It is a geometric similarity score under the chosen representation. Relevance and factual support need their own evaluation.
Evidence, mistakes & handover
Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.
Authoritative reference
— official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.
Try the activity before reading its reference. Keep your sources, commands and assumptions with your work. Companion activities are unsaved self-practice and do not award a certificate or change lesson progress.