Build Your Own Local NMT App with React Native and QVAC
This article explores how Neural Machine Translation (NMT), powered by the Transformer architecture, revolutionized translation by understanding context. We then delve into QVAC, a local-first AI development platform, and its Bergamot engine, enabling private, on-device translation. Learn to set up a React Native app with QVAC and manage model lifecycles for efficient local translation.

For years, machine translation often felt clunky, delivering stiff, robotic output. This began to change dramatically in June 2017 with the release of "Attention Is All You Need," a seminal paper by eight Google researchers. This work introduced the Transformer architecture, a foundational framework that powers today's large language models, including ChatGPT. It marked a profound shift, enabling translation systems to grasp not just individual word meanings, but their semantic context within an entire sentence.
Consider the word "bank." An older system might struggle with its dual meaning in "I can't make the bank deposit today" versus "We shall meet near the river bank." Modern Neural Machine Translation (NMT) understands these nuances, discerning between a financial institution and land beside water. This article will demystify NMT and the Transformer, then guide you through building your own context-aware translation app using React Native and the QVAC SDK.
Demystifying NMT: The Brain Behind the Screen
Before NMT, computer translation largely relied on rule-based systems: massive bilingual dictionaries coupled with grammar rules. This approach translated word-by-word, often leading to awkward, inflexible results. NMT revolutionized this by employing Neural Networks, systems inspired by the human brain. Instead of rigid rules, NMT learns from millions of existing human translations, identifying patterns and understanding how words truly interact in diverse contexts. Early NMT systems, however, processed sentences sequentially, leading to a "forgetting" issue in longer texts.
How the Transformer Sees the World
To overcome the sequential memory problem, the "Attention Is All You Need" paper introduced the Transformer architecture. This groundbreaking design processes an entire sentence simultaneously, dividing the task into two core components: the Encoder and the Decoder.
The Encoder (The Reader)
The Encoder acts as a sophisticated reader, generating a comprehensive "mental map" of a sentence's meaning. It achieves this using Self-Attention, a mechanism that allows the system to weigh the relevance of every other word in a sentence when processing a specific word. For example, when the Encoder processes "bank" in "We shall meet near the river bank," its Self-Attention mechanism highlights "river," immediately establishing the correct semantic meaning (land next to water) before proceeding.
The Decoder (The Writer)
Once the Encoder's blueprint of the sentence's meaning is complete, it's passed to the Decoder. The Decoder's role is to construct the translated sentence word-by-word, constantly referencing the Encoder's blueprint via Cross-Attention. This ensures consistency in context, tone, and grammar. In our "river bank" example, the Decoder would correctly output "la rive" (river bank) in French, rather than "la banque" (financial bank), due to the Encoder's initial contextual understanding.
Why This Matters
By teaching machines to comprehend the broader context of language, Google's engineers didn't just enhance translation; they laid the groundwork for the modern AI era. This ability to understand linguistic context is the very foundation upon which large language models are built, enabling them to generate essays, answer complex questions, and even write code.
The Democratization of AI with QVAC
Initially, leveraging Transformer-based AI was an expensive endeavor, dominated by large tech companies. Independent developers faced significant barriers due to high costs and a lack of accessible resources. Understanding the underlying mathematics often required specialized academic knowledge.
However, the open-source community, coupled with advancements in personal device processors, has democratized AI. Powerful models are now freely available, and sophisticated AI can run locally on smartphones. This ensures maximum data privacy and eliminates reliance on external servers. To demonstrate this, we'll build an English-to-French translation app using Expo and QVAC.
What is QVAC?
QVAC (QuantumVerse Automatic Computer) is a decentralized, local-first AI development platform and SDK from Tether. It enables AI models to run entirely on users' devices, ensuring data privacy, security, and user control by keeping computation local and offline.
Key Concepts for On-Device Translation
- On-Device Inference: QVAC supports specialized local inference backends for different tasks. For translation, it uses the Bergamot engine, which memory-maps quantized model weights directly into device RAM, leveraging native hardware acceleration.
- Quantization: This mathematical optimization technique compresses model weights, allowing models to fit within mobile hardware memory constraints while maintaining high output quality.
The Architecture Supported by QVAC
The QVAC SDK manages hardware binding and the model lifecycle, integrating with optimized inference backends like Bergamot. The Bergamot engine, known for powering Firefox's offline translation, is highly optimized for fast, accurate NMT on consumer devices. It processes source sentences through its Encoder-Decoder Transformer architecture to predict target language tokens efficiently.
Understanding Language Pairs
Translation models like Bergamot's are typically unidirectional language pairs. For instance, the BERGAMOT_EN_FR model translates exclusively from English to French; a separate model is required for French-to-English translation. This specialization keeps model sizes incredibly small (15-35MB), as the neural network only needs to "understand" one input language and "generate" one output language, rather than storing vast representations for multiple linguistic directions, which would dramatically increase parameter count, file size, and computational demands.
The Inference Pipeline
Interacting with a local translation engine via QVAC can be visualized as a dedicated interpreter running directly in your phone's memory:
- Hiring the interpreter (loading the model): The compressed model file (e.g.,
BERGAMOT_EN_FR) is memory-mapped into the device's RAM. - Handing over the script (text input): The source text is passed to the loaded engine.
- The performance (inference): The engine mathematically predicts and provides the translated tokens.
- Closing the show (unloading): To free up memory-intensive resources, the model can be cleared from RAM once translation is complete or when it's no longer needed.
Setting Up the Project and Core Implementation
To get started, initialize an Expo project and install the necessary QVAC dependencies:
bash npx create-expo-app translator-app --template blank-typescript cd translator-app npm install @qvac/sdk jiti
Next, add the required peer dependencies to your package.json:
"dependencies": { "bare-rpc": "^1.0.0", "react-native-bare-kit": "^0.11.5" }, "devDependencies": { "bare-pack": "^1.5.1" }
Then install them:
bash npm install npx expo install expo-file-system expo-build-properties expo-device
Configure the QVAC SDK plugin in your app.config.js. We use jiti to bridge between Expo's CommonJS environment and the QVAC SDK's modern ECMAScript Module (ESM) plugin:
javascript const createJiti = require("jiti"); const jiti = createJiti(__filename);
const qvacModule = jiti("@qvac/sdk/expo-plugin"); const withQvacSDK = qvacModule.withQvacSDK || qvacModule.default;
module.exports = ({ config }) => { config.plugins = [ [ "expo-build-properties", { android: { minSdkVersion: 29 }, }, ], withQvacSDK, "expo-router", [ "expo-splash-screen", { backgroundColor: "#208AEF", }, ], ]; return config; };
Within your application logic, managing the native model lifecycle is crucial. You'd typically use getModelInfo to check if a model is already isCached on the device, avoiding unnecessary downloads:
typescript const model = await getModelInfo({ name: BERGAMOT_EN_FR.name }); setIsDownloaded(model.isCached);
The loadModel function handles the download from Hugging Face if not cached, then memory-maps its weights. The onProgress callback provides download status for UI updates. Once loaded, the translate function takes your input text and the modelId to perform the translation. After use, unloadModel efficiently clears the model from RAM, freeing up resources. This lifecycle management ensures efficient local execution and a smooth user experience.
For example, translating "The location I told you was near the river bank" would correctly yield "L'endroit où je vous ai dit était près de la rive de la rivière" in French.
Conclusion
By leveraging NMT and the QVAC SDK, developers can now create sophisticated, private, and performant translation applications that run entirely on users' devices. This shift not only enhances data security but also signifies the growing accessibility of powerful AI capabilities, moving from server-dependent giants to local-first solutions that fit in a user's pocket.
FAQ
Q: Why are QVAC translation models typically unidirectional (e.g., English to French only)?
A: Unidirectional models like Bergamot's are highly specialized. They only store the mathematical representations and grammar rules needed to translate from one specific source language to one specific target language. This extreme specialization significantly reduces the model's parameter count and file size (to 15-35MB), making it feasible to run efficiently on consumer mobile hardware without heavy RAM or compute power.
Q: How does QVAC ensure data privacy for on-device translation?
A: QVAC ensures data privacy by performing all AI model calculations entirely on the user's device. Unlike cloud-based APIs, no data leaves the device, keeping information secure and under the user's control. This local-first approach is fundamental to QVAC's design.
Q: What is the purpose of jiti when configuring the QVAC SDK plugin in Expo?
A: The QVAC SDK's Expo plugin is distributed as a modern ECMAScript Module (ESM). However, Expo's configuration file (app.config.js) runs in a standard Node.js CommonJS environment. jiti acts as a bridge, enabling app.config.js to synchronously load ESM modules without causing build errors, allowing the QVAC plugin to be correctly applied.
Related articles
Kimi K3 Review: An Open-Source AI Challenger Worth Watching
Kimi K3 Review: An Open-Source AI Challenger Worth Watching Quick Verdict: Moonshot's Kimi K3 emerges as a compelling open-source alternative in the rapidly evolving AI landscape. While its overall performance might not
ASML Low-NA EUV Pricing: Value Capture or Cost Burden
The Industry Reacts: ASML's EUV Pricing Shift Verdict: ASML’s strategic move to broaden its value-based pricing for Low-NA EUV tools, looking beyond mere wafer throughput, marks a significant shift in the semiconductor
Gemini Voice Customization: Your AI, Your Tone
Gemini review: Google's upcoming voice customization offers granular control over Energy, Formality, Warmth, and Speed, marking a shift towards truly personal AI interaction. This beta-discovered feature promises more natural and consistent user experiences, putting Google in a strong position in the evolving AI landscape.
Unpacking Roman Concrete's Durability: Carbonation and Self-Healing
The Enduring Legacy: Roman Concrete's Millennia-Long Stand As software developers, we're familiar with the ephemeral nature of technology; systems evolve, frameworks deprecate, and codebases undergo constant
PayPal in Microservices: NestJS, gRPC, and Docker Blueprint
Integrating payment logic directly into every microservice within a distributed system often leads to significant challenges. Scattering PayPal API calls across services like user-service, order-service, or
How to Reclaim 22GB on Your Samsung Phone Without Deleting Important
Learn to effectively free up significant storage space on your Samsung phone by emptying trash, removing duplicates, archiving apps, clearing caches, and managing offline files in just a few steps, without sacrificing your essential data.





