{"id":277532,"date":"2025-05-28T14:26:04","date_gmt":"2025-05-28T14:26:04","guid":{"rendered":"https:\/\/michigandigitalnews.com\/index.php\/2025\/05\/28\/on-device-genai-apis-as-part-of-ml-kit-help-you-easily-build-with-gemini-nano\/"},"modified":"2025-06-25T17:08:15","modified_gmt":"2025-06-25T17:08:15","slug":"on-device-genai-apis-as-part-of-ml-kit-help-you-easily-build-with-gemini-nano","status":"publish","type":"post","link":"https:\/\/michigandigitalnews.com\/index.php\/2025\/05\/28\/on-device-genai-apis-as-part-of-ml-kit-help-you-easily-build-with-gemini-nano\/","title":{"rendered":"On-device GenAI APIs as part of ML Kit help you easily build with Gemini Nano"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div>\n<meta content=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEh96stpV5BvqzxBhk12xYFEg5g-5U4H93DJOId6MEDioi_kPsXWnW3tBwd_kYQfIrcaD4h6QF3cylN62tkiTMit-K6haiB8QSJ2Lnp9ggL_bY_hNwu-FX3HquDmZ98rMYoyug6PxJ0qQQ2_7hlB1BfhZXvh8IFweZJDRbplE0CdwrjjOsMH1GKfC_6hHXo\/s1600\/gen-ai-api-android-meta%20%283%29.png\" name=\"twitter:image\"\/><br \/>\n<img decoding=\"async\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEh96stpV5BvqzxBhk12xYFEg5g-5U4H93DJOId6MEDioi_kPsXWnW3tBwd_kYQfIrcaD4h6QF3cylN62tkiTMit-K6haiB8QSJ2Lnp9ggL_bY_hNwu-FX3HquDmZ98rMYoyug6PxJ0qQQ2_7hlB1BfhZXvh8IFweZJDRbplE0CdwrjjOsMH1GKfC_6hHXo\/s1600\/gen-ai-api-android-meta%20%283%29.png\" style=\"display: none;\"\/><\/p>\n<p><em>Posted by Caren Chang &#8211; Developer Relations Engineer, Chengji Yan &#8211; Software Engineer, Taj Darra &#8211; Product Manager<\/em><\/p>\n<p><a href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjUnecK6GCD0zX60dSKM1fspl7RcCZh3kaWG-PYKw3Yf4Vyf_3NXlsQoRAVQ_milOQqfBS6gtDODFwK5b9SskqFT7tu6fYDr8WcqxuJQxqIrA9L8VVVsxgSGJogtFqgFe0wVZswvVjTU1Zuf1-ZkAT_bPXL29iIVooQzoStIDZEbaVA0ygvoggMoMsCXrM\/s1600\/gen-ai-api-android-hero%20%281%29.png\"><img decoding=\"async\" border=\"0\" data-original-height=\"800\" data-original-width=\"100%\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjUnecK6GCD0zX60dSKM1fspl7RcCZh3kaWG-PYKw3Yf4Vyf_3NXlsQoRAVQ_milOQqfBS6gtDODFwK5b9SskqFT7tu6fYDr8WcqxuJQxqIrA9L8VVVsxgSGJogtFqgFe0wVZswvVjTU1Zuf1-ZkAT_bPXL29iIVooQzoStIDZEbaVA0ygvoggMoMsCXrM\/s1600\/gen-ai-api-android-hero%20%281%29.png\"\/><\/a><\/p>\n<p>We are excited to announce a set of on-device <a href=\"https:\/\/developers.google.com\/ml-kit\/genai\" target=\"_blank\" rel=\"noopener\">GenAI APIs, as part of ML Kit<\/a>, to help you integrate Gemini Nano in your Android apps.<\/p>\n<p>To start, we are releasing 4 new APIs:<\/p>\n<ul>\n<ul>\n<li><b>Summarization<\/b>: to summarize articles and conversations<\/li>\n<li><b>Proofreading<\/b>: to polish short text<\/li>\n<li><b>Rewriting<\/b>: to reword text in different styles<\/li>\n<li><b>Image Description<\/b>: to provide short description for images<\/li>\n<\/ul>\n<\/ul>\n<h2><span style=\"font-size: x-large;\">Key benefits of GenAI APIs<\/span><\/h2>\n<p>GenAI APIs are high level APIs that allow for easy integration, similar to existing <a href=\"https:\/\/developers.google.com\/ml-kit\" target=\"_blank\" rel=\"noopener\">ML Kit APIs<\/a>. This means you can expect quality results out of the box without extra effort for prompt engineering or fine tuning for specific use cases.<\/p>\n<p>GenAI APIs run on-device and thus provide the following benefits:<\/p>\n<ul>\n<ul>\n<li>Input, inference, and output data is processed locally<\/li>\n<li>Functionality remains the same without reliable internet connection<\/li>\n<li>No additional cost incurred for each API call<\/li>\n<\/ul>\n<\/ul>\n<p>To prevent misuse, we also added safety protection in various layers, including base model training, safety-aware LoRA fine-tuning, input and output classifiers and safety evaluations.<\/p>\n<h2><span style=\"font-size: x-large;\">How GenAI APIs are built<\/span><\/h2>\n<p>There are 4 main components that make up each of the GenAI APIs.<\/p>\n<ol>\n<li>Gemini Nano is the base model, as the foundation shared by all APIs.<\/li>\n<li>Small API-specific LoRA adapter models are trained and deployed on top of the base model to further improve the quality for each API.<\/li>\n<li>Optimized inference parameters (e.g. prompt, temperature, topK, batch size) are tuned for each API to guide the model in returning the best results.<\/li>\n<li>An evaluation pipeline ensures quality in various datasets and attributes. This pipeline consists of: LLM raters, statistical metrics and human raters.<\/li>\n<\/ol>\n<p>Together, these components make up the high-level GenAI APIs that simplify the effort needed to integrate Gemini Nano in your Android app.<\/p>\n<h2><span style=\"font-size: x-large;\">Evaluating quality of GenAI APIs<\/span><\/h2>\n<p>For each API, we formulate a benchmark score based on the evaluation pipeline mentioned above. This score is based on attributes specific to a task. For example, when evaluating the summarization task, one of the attributes we look at is \u201cgrounding\u201d (ie: factual consistency of generated summary with source content).<\/p>\n<p>To provide out-of-box quality for GenAI APIs, we applied feature specific fine-tuning on top of the Gemini Nano base model. This resulted in an increase for the benchmark score of each API as shown below:<\/p>\n<table style=\"width: 100%;\">\n<tbody>\n<tr>\n<th style=\"text-align: left;\"><b>Use case in English<\/b><\/th>\n<th style=\"text-align: left;\">Gemini Nano Base Model<\/th>\n<th style=\"text-align: left;\">ML Kit GenAI API<\/th>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Summarization<\/td>\n<td style=\"text-align: left;\">77.2<\/td>\n<td style=\"text-align: left;\">92.1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Proofreading<\/td>\n<td style=\"text-align: left;\">84.3<\/td>\n<td style=\"text-align: left;\">90.2<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Rewriting<\/td>\n<td style=\"text-align: left;\">79.5<\/td>\n<td style=\"text-align: left;\">84.1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Image Description<\/td>\n<td style=\"text-align: left;\">86.9<\/td>\n<td style=\"text-align: left;\">92.3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In addition, this is a quick reference of how the APIs perform on a Pixel 9 Pro:<\/p>\n<table style=\"width: 100%;\">\n<tbody>\n<tr>\n<th style=\"text-align: left;\"\/>\n<th style=\"text-align: left;\"><b>Prefix Speed<br \/>(input processing rate)<\/b><\/th>\n<th style=\"text-align: left;\"><b>Decode Speed<br \/>(output generation rate)<\/b><\/th>\n<\/tr>\n<tr>\n<td style=\"text-align: left; width: 20%;\">Text-to-text<\/td>\n<td style=\"text-align: left; width: 40%;\">510 tokens\/second<\/td>\n<td style=\"text-align: left; width: 40%;\">11 tokens\/second<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left; width: 20%;\">Image-to-text<\/td>\n<td style=\"text-align: left; width: 40%;\">510 tokens\/second + 0.8 seconds for image encoding<\/td>\n<td style=\"text-align: left; width: 40%;\">11 tokens\/second<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span style=\"font-size: x-large;\">Sample usage<\/span><\/h2>\n<p>This is an example of implementing the GenAI Summarization API to get a one-bullet summary of an article:<\/p>\n<p><!--Kotlin--><\/p>\n<div style=\"background: rgb(248, 248, 248); border: 0px; overflow: auto; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0px;\"><span style=\"color: green; font-weight: bold;\">val<\/span> articleToSummarize = <span style=\"color: #ba2121;\">\"We are excited to announce a set of on-device generative AI APIs...\"<\/span>\n\n<span style=\"color: #408080; font-style: italic;\">\/\/ Define task with desired input and output format<\/span>\n<span style=\"color: green; font-weight: bold;\">val<\/span> summarizerOptions = SummarizerOptions.builder(context)\n    .setInputType(InputType.ARTICLE)\n    .setOutputType(OutputType.ONE_BULLET)\n    .setLanguage(Language.ENGLISH)\n    .build()\n<span style=\"color: green; font-weight: bold;\">val<\/span> summarizer = Summarization.getClient(summarizerOptions)\n\nsuspend <span style=\"color: green; font-weight: bold;\">fun<\/span> <span style=\"color: blue;\">prepareAndStartSummarization<\/span>(context: Context) {\n    <span style=\"color: #408080; font-style: italic;\">\/\/ Check feature availability. Status will be one of the following: <\/span>\n    <span style=\"color: #408080; font-style: italic;\">\/\/ UNAVAILABLE, DOWNLOADABLE, DOWNLOADING, AVAILABLE<\/span>\n    <span style=\"color: green; font-weight: bold;\">val<\/span> featureStatus = summarizer.checkFeatureStatus().await()\n\n    <span style=\"color: green; font-weight: bold;\">if<\/span> (featureStatus == FeatureStatus.DOWNLOADABLE) {\n        <span style=\"color: #408080; font-style: italic;\">\/\/ Download feature if necessary.<\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ If downloadFeature is not called, the first inference request will <\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ also trigger the feature to be downloaded if it's not already<\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ downloaded.<\/span>\n        summarizer.downloadFeature(object : DownloadCallback {\n            <span style=\"color: green; font-weight: bold;\">override<\/span> <span style=\"color: green; font-weight: bold;\">fun<\/span> <span style=\"color: blue;\">onDownloadStarted<\/span>(bytesToDownload: Long) { }\n\n            <span style=\"color: green; font-weight: bold;\">override<\/span> <span style=\"color: green; font-weight: bold;\">fun<\/span> <span style=\"color: blue;\">onDownloadFailed<\/span>(e: GenAiException) { }\n\n            <span style=\"color: green; font-weight: bold;\">override<\/span> <span style=\"color: green; font-weight: bold;\">fun<\/span> <span style=\"color: blue;\">onDownloadProgress<\/span>(totalBytesDownloaded: Long) {}\n\n            <span style=\"color: green; font-weight: bold;\">override<\/span> <span style=\"color: green; font-weight: bold;\">fun<\/span> <span style=\"color: blue;\">onDownloadCompleted<\/span>() {\n                startSummarizationRequest(articleToSummarize, summarizer)\n            }\n        })    \n    } <span style=\"color: green; font-weight: bold;\">else<\/span> <span style=\"color: green; font-weight: bold;\">if<\/span> (featureStatus == FeatureStatus.DOWNLOADING) {\n        <span style=\"color: #408080; font-style: italic;\">\/\/ Inference request will automatically run once feature is      <\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ downloaded.<\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ If Gemini Nano is already downloaded on the device, the   <\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ feature-specific LoRA adapter model will be downloaded very  <\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ quickly. However, if Gemini Nano is not already downloaded, <\/span>\n        <span style=\"color: #408080; font-style: italic;\">\/\/ the download process may take longer.<\/span>\n        startSummarizationRequest(articleToSummarize, summarizer)\n    } <span style=\"color: green; font-weight: bold;\">else<\/span> <span style=\"color: green; font-weight: bold;\">if<\/span> (featureStatus == FeatureStatus.AVAILABLE) {\n        startSummarizationRequest(articleToSummarize, summarizer)\n    } \n}\n\n<span style=\"color: green; font-weight: bold;\">fun<\/span> <span style=\"color: blue;\">startSummarizationRequest<\/span>(text: String, summarizer: Summarizer) {\n    <span style=\"color: #408080; font-style: italic;\">\/\/ Create task request  <\/span>\n    <span style=\"color: green; font-weight: bold;\">val<\/span> summarizationRequest = SummarizationRequest.builder(text).build()\n\n    <span style=\"color: #408080; font-style: italic;\">\/\/ Start summarization request with streaming response<\/span>\n    summarizer.runInference(summarizationRequest) { newText -&gt; \n        <span style=\"color: #408080; font-style: italic;\">\/\/ Show new text in UI<\/span>\n    }\n\n    <span style=\"color: #408080; font-style: italic;\">\/\/ You can also get a non-streaming response from the request<\/span>\n    <span style=\"color: #408080; font-style: italic;\">\/\/ val summarizationResult = summarizer.runInference(summarizationRequest)<\/span>\n    <span style=\"color: #408080; font-style: italic;\">\/\/ val summary = summarizationResult.get().summary<\/span>\n}\n\n<span style=\"color: #408080; font-style: italic;\">\/\/ Be sure to release the resource when no longer needed<\/span>\n<span style=\"color: #408080; font-style: italic;\">\/\/ For example, on viewModel.onCleared() or activity.onDestroy()<\/span>\nsummarizer.close()\n<\/pre>\n<\/div>\n<p>For more examples of implementing the GenAI APIs, check out the official <a href=\"https:\/\/developers.google.com\/ml-kit\/genai\" target=\"_blank\" rel=\"noopener\">documentation<\/a> and samples on GitHub:<\/p>\n<h2><span style=\"font-size: x-large;\">Use cases<\/span><\/h2>\n<p>Here is some guidance on how to best use the current GenAI APIs:<\/p>\n<p>For <b>Summarization<\/b>, consider:<\/p>\n<ul>\n<ul>\n<li>Conversation messages or transcripts that involve 2 or more users<\/li>\n<\/ul>\n<ul>\n<li>Articles or documents less than 4000 tokens (or about 3000 English words). Using the first few paragraphs for summarization is usually good enough to capture the most important information.<\/li>\n<\/ul>\n<\/ul>\n<p>For <b>Proofreading<\/b> and <b>Rewriting<\/b> APIs, consider utilizing them during the content creation process for short content below 256 tokens to help with tasks such as:<\/p>\n<ul>\n<ul>\n<li>Refining messages in a particular tone, such as more formal or more casual<\/li>\n<\/ul>\n<ul>\n<li>Polishing personal notes for easier consumption later<\/li>\n<\/ul>\n<\/ul>\n<p>For the <b>Image Description<\/b> API, consider it for:<\/p>\n<ul>\n<ul>\n<li>Generating titles of images<\/li>\n<\/ul>\n<ul>\n<li>Generating metadata for image search<\/li>\n<\/ul>\n<ul>\n<li>Utilizing descriptions of images in use cases where the images themselves cannot be displayed, such as within a list of chat messages<\/li>\n<\/ul>\n<ul>\n<li>Generating alternative text to help visually impaired users better understand content as a whole<\/li>\n<\/ul>\n<\/ul>\n<h2><span style=\"font-size: x-large;\">GenAI API in production<\/span><\/h2>\n<p>Envision is an app that verbalizes the visual world to help people who are blind or have low vision lead more independent lives. A common use case in the app is for users to take a picture to have a document read out loud. Utilizing the GenAI Summarization API, Envision is now able to get a concise summary of a captured document. This significantly enhances the user experience by allowing them to quickly grasp the main points of documents and determine if a more detailed reading is desired, saving them time and effort.<\/p>\n<p><image><\/p>\n<div style=\"text-align: center;\"><img fetchpriority=\"high\" decoding=\"async\" alt=\"side by side images of a mobile device showing a document on a table on the left, and the results of the scanned document on the right showing details providing the what, when, and where as written in the document\" border=\"0\" height=\"613\" id=\"imgCaption\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgkOrO3R_GVdd26XH3C6XcLCgJ39SYS4z6i4spYGRPo8Z0uJtmwmnzejROH0b__EnZqxQ7rRfZiUCb2qYodgZCUCht43LaC0KCO2VGVtDSqcjc-eJ7Vp6f8U6qToWOakAqhflG0_e2t9fWa7JYdx26ykZZFqbVwTOYOroHmjoDRsxM2KzZmAU7CM2I_fuo\/w640-h613\/generative-api-in-action-android-envision.png\" width=\"640\"\/><\/div>\n<p><\/image><\/p>\n<h2><span style=\"font-size: x-large;\">Supported devices<\/span><\/h2>\n<p>GenAI APIs are available on Android devices using optimized MediaTek Dimensity, Qualcomm Snapdragon, and Google Tensor platforms through AICore. For a comprehensive list of devices that support GenAI APIs, refer to our <a href=\"https:\/\/developers.google.com\/ml-kit\/genai#device-support\" target=\"_blank\" rel=\"noopener\">official documentation<\/a>.<\/p>\n<h2><span style=\"font-size: x-large;\">Learn more<\/span><\/h2>\n<p>Start implementing GenAI APIs in your Android apps today with guidance from our official <a href=\"https:\/\/developers.google.com\/ml-kit\/genai\" target=\"_blank\" rel=\"noopener\">documentation<\/a> and samples on GitHub: <a href=\"https:\/\/github.com\/android\/ai-samples\/tree\/main\/ai-catalog\/samples\" target=\"_blank\" rel=\"noopener\">AI Catalog GenAI API Samples with Compose, ML Kit GenAI APIs Quickstart<\/a>.<\/p>\n<\/div>\n<p>[ad_2]<br \/>\n<br \/><a href=\"http:\/\/android-developers.googleblog.com\/2025\/05\/on-device-gen-ai-apis-ml-kit-gemini-nano.html\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Posted by Caren Chang &#8211; Developer Relations Engineer, Chengji Yan &#8211; Software Engineer, Taj Darra &#8211; Product Manager We are excited to announce a<\/p>\n","protected":false},"author":1,"featured_media":277533,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[146],"tags":[],"_links":{"self":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts\/277532"}],"collection":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/comments?post=277532"}],"version-history":[{"count":0,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts\/277532\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/media\/277533"}],"wp:attachment":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/media?parent=277532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/categories?post=277532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/tags?post=277532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}