Huawei Developers
Published in

Huawei Developers

Expert: Integrating Text Embedding in Xamarin (Android) using Huawei ML Kit

What is Text Embedding?

Text Embedding is a class of techniques where individual words are represented as real-value vectors in a predefined vector space. In this technique, each word is mapped with one vector.

Introduction

Huawei ML Kit provides Text Embedding feature which helps to get matching vector value of words or sentences. Using this feature, we can improve our research based on the result. It provides similarity between two words or sentences and similar words of a particular word searched. We can also improve searching and browsing efficiency using after getting result related to search text.

Let us start with the project configuration part:

Step 1: Create an app on App Gallery Connect.

Step 2: Enable the ML Kit in Manage APIs menu.

Step 3: Create new Xamarin (Android) project.

Step 4: Change your app package name same as AppGallery app’s package name.

  • Right click on your app in Solution Explorer and select properties.
  • Select Android Manifest on lest side menu.
  • Change your Package name as shown in below image.

Step 5: Generate SHA 256 key.

  • Select Build Type as Release.
  • Right click on your app in Solution Explorer and select Archive.
  • If Archive is successful, click on Distribute button as shown in below image.
  • Select Ad Hoc.
  • Click Add Icon.
  • Enter the details in Create Android Keystore and click on Create button.
  • Double click on your created keystore and you will get your SHA 256 key. Save it.
  • Add the SHA 256 key to App Gallery.

Step 6: Sign the .APK file using the keystore for Release configuration.

  • Right-click on your app in Solution Explorer and select properties.
  • Select Android Packaging Signing and add the Keystore file path and enter details as shown in image.

Step 7: Enable the Service.

Step 8: Install Huawei ML NuGet Package.

Step 9: Install Huawei.Hms.MlNlpTextembedding package using Step 8.

Step 10: Integrate HMS Core SDK.

Step 11: Add SDK Permissions.

Let us start with the implementation part:

Step 1: Create activity_main.xml for Text Similarity, Sentence Similarity and Similar Word buttons.

Step 2: Create MainActivity.cs for button click listener.

Step 3: Initialize MLtextEmbedding inside MainActivity.cs OnCreate() method.

Word Similarity Implementation

Step 1: Create word_similarity.xml.

Step 2: Create WordSimilarActivity.cs for getting similarity between two words.

Sentence Similarity Implementation

Step 1: Create sentence_similarity.xml.

Step 2: Create SentenceSimilarActivity.cs for getting similarity between two sentences.

Similar Word Implementation

Step 1: Create similar_words.xml.

Step 2: Create FindSimilarWordActivity.cs for getting the similar word of a particular word search.

Now Implementation part done.

Result

Tips and Tricks

  1. Do not forget to add internet permission in AndroidManifest.xml file as Text Embedding feature depends on-cloud API for recognition.

2. Please use Manifest Merger inside ProjectName > ProjectName.csproj file.

3. Please set API Key inside MainActivity.cs OnCreate() method.

Conclusion

In this article, we have learnt about getting the similarity between two words or sentences and also getting the similar words of a particular word search. This helps to improve user search experience.

Thanks for reading! If you enjoyed this story, please provide Likes and Comments.

Reference

Implementing ML Kit Text Embedding

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store