Implementing custom skills and leveraging them in a skillset is instrumental when designing and implementing AI solutions on Microsoft Azure. Custom skills empower developers to extend the capabilities of Azure Cognitive Search by creating their own processing steps, tailored to their specific needs. In the context of the AI-102 exam, it is important to understand this process and how custom skills are integrated into a Cognitive Search architecture.

Table of Contents

Understanding Custom Skills

Custom skills in Microsoft Azure are web API skills which allow you to embed your own machine learning models or custom information retrieval routines into a skillset, thus broadening the scope of what Azure cognitive search can do out-of-the-box.

Creating custom skills offers two main advantages:

  • Leveraging existing models: Developers can leverage existing machine learning models, by incorporating them into the Cognitive Search pipeline.
  • Meeting unique needs: Skills can be designed to meet unique needs that are not covered by the pre-defined skillset.

Process to Implement Custom Skills

The process to implement a custom skill in Azure can be resumed in three steps:

  1. Creation of the Custom Skill: Essentially a stateless web API, the custom skill can be written in any language and hosted anywhere. The important point to remember is that the custom skill must accept HTTP POST operations.
  2. Inclusion in the Skillset: To leverage the custom skill, developers must include it in the Azure Cognitive Search indexer skillset definition.
  3. Test Custom Skills: Ensuring that the custom skill can correctly process input and output in the required format is a crucial step.

Example: Implementing a Custom Skill for Entity Recognition

Let’s take a simple example: suppose we need to create a custom skill for entity recognition in text. We would define the skill as a Web API method that accepts POST requests. Here we consider an example in Python, although you are free to use any language:

from flask import Flask, request
from my_custom_nlp_lib import recognize_entities

app = Flask(__name__)

@app.route('/api/recognizeEntities', methods=['POST'])
def handle():
try:
values = request.get_json()
text = values['values'][0]['data']['text']
entities = recognize_entities(text)
return {'values': [{'recordId': '0', 'data': {'entities': entities}}]}
except Exception as e:
return {'error': str(e)}

if __name__ == '__main__':
app.run()

In this example, my_custom_nlp_lib.recognize_entities(text) is a hypothetical function that applies a named-entity recognition model to a text string. The web API parses the input, applies the NLP model, and returns recognized entities in the specified output format.

Once we’ve created the custom skill, we can include it in an Azure Cognitive Search skillset. In the skills array of a skillset definition, we would add a new skill as follows:

{
"@odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
"description": "Our custom entity recognition skill",
"context": "/document",
"uri": "http://.azurewebsites.net/api/recognizeEntities",
"batchSize": 1,
"inputs": [
{
"name": "text",
"source": "/document/content"
}
],
"outputs": [
{
"name": "entities",
"targetName": "entities"
}
]
}

Inclusion of the custom skill into an existing skillset allows Azure Cognitive Search to utilize it to analyze and enrich your content. Always remember to appropriately test your custom skills to ensure they are working as expected.

In the context of AI-102 exam, having a practical understanding of this process can be immensely helpful. Microsoft Azure provides the flexibility and capabilities enabling you to build highly customized solutions.

Practice Test

True or False: Custom skills are AI abilities that are manually implemented by developers in a cognitive search solution.

Answer: True

Explanation: Custom skills in Azure AI are AI abilities implemented by the developers to create solutions that do not exist in pre-built cognitive skills.

Can you include custom skills in skillsets while creating a Cognitive Search pipeline on Microsoft Azure?

  • A) Yes
  • B) No

Answer: A) Yes

Explanation: Custom skills can indeed be incorporated into skillsets while creating a search pipeline. This allows for integration of custom processing into the pipeline.

True or False: Custom skills must always be written in Python.

Answer: False

Explanation: Custom skills can be written in any language that can receive and send HTTP requests/responses.

In terms of setting up custom skills, what is an ‘execution context’?

  • A) The cloud environment where the skill is hosted
  • B) The local development environment
  • C) The skill’s name and description
  • D) The input and output shapes of the skill

Answer: A) The cloud environment where the skill is hosted

Explanation: An execution context, in relation to custom skills, refers to the cloud environment where the skill is hosted.

Multiple Select: What needs to be defined when implementing a custom skill?

  • A) Input/output interfaces
  • B) Execution context
  • C) Language support
  • D) Price Range

Answer: A) Input/output interfaces, B) Execution context

Explanation: While implementing a custom skill, the input/output interfaces and the execution context must be defined.

True or False: Custom skills can be implemented using the Azure Machine Learning service.

Answer: True

Explanation: Azure Machine Learning service can be used to implement custom skills, which can then be incorporated into a cognitive search solution.

What is the role of a ‘Shape’ in the context of custom skills?

  • A) Defines the execution context
  • B) Defines the input and output data types of the skill
  • C) Defines the language of the skill
  • D) None of the above

Answer: B) Defines the input and output data types of the skill

Explanation: A ‘Shape’ in the context of custom skills defines the input and output data types of the skill.

True or False: Custom skills cannot be included in a skillset to process data extracted by cognitive search.

Answer: False

Explanation: Custom skills can be included in a skillset to analyze and process data extracted by cognitive search.

Who is responsible for maintaining and monitoring the execution context for a custom skill?

  • A) Microsoft Azure
  • B) The developer implementing the skill
  • C) The user executing the search
  • D) All of the above

Answer: B) The developer implementing the skill

Explanation: The developer deploying the custom skill is responsible for maintaining and monitoring the execution context for the skill.

True or False: You can implement a custom skill in Java.

Answer: True

Explanation: You can write a custom skill in any language that can send and receive HTTP requests/responses, which includes Java.

Interview Questions

What is a custom skill in the context of Azure Cognitive Search?

A custom skill is a user-defined function that performs a specific action or calculation for inclusion in a skillset during AI enrichment.

How do you include a custom skill in a skillset?

To include a custom skill in a skillset, you need to specify it in your skillset definition. You have to include inputs and outputs for the custom skill, the context, and the Web API endpoint the skill will point to.

What are the primary components of a custom skill?

A custom skill mainly has three components: inputs, outputs, and a context. The inputs define the data that will be used, the outputs define what the skill will return, and the context is used to specify the document structure.

What is a Web API endpoint in the context of a custom skill?

A Web API endpoint refers to a RESTful API which your custom skill code listens to. When invoked during an enrichment pipeline, the Cognitive Search Service sends a request to this endpoint with the input data.

How can you secure your Web API for custom skill?

You can secure your Web API by implementing an authorization layer in your Azure Function, leveraging mechanisms such as Azure Active Directory.

What languages are supported for writing custom skills?

You can write custom skills in any language that you can use to create a RESTful Web API, such as C#, JavaScript, Python, Java, etc.

What is the main function of the “context” in a custom skill?

The “context” in a custom skill provides a way to specify the parts of the document that the skill should run over. You use context to establish a path to the input elements.

Can you add more than one custom skill in a skillset?

Yes, you can add multiple custom skills in a skillset. The output of one skill could be fed as an input to another, allowing complex enrichment scenarios.

What is the maximum time limit for a custom skill execution?

As per Azure documentation, the maximum time allowed for an individual custom skill execution is 230 seconds.

Can I use external third-party APIs as my custom skill?

Yes, you can design your custom skill to call out to third-party APIs to perform a particular action or calculation, and then use the response as an output of the skill.

What is the structure of a request from Azure Cognitive Search to a custom skill’s Web API?

It’s a POST request with a JSON body. The JSON body contains a ‘values’ array that consists of one or more ‘record’ objects. Each record objects contains ‘recordId’, ‘data’ with input data, and optionally ‘errors’ and ‘warnings’.

Can a custom skill access Azure storage account data?

No, a custom skill can’t directly access Azure storage account data. It can only process data passed to it in the request.

What is “OData type” in the inputs and outputs of a custom skill?

The “OData type” in the inputs and outputs of a custom skill is used to describe the content type of the input or output. It allows the skill to handle different types of data, such as text, images, etc.

Can a custom skill return errors and warnings?

Yes, a custom skill can return errors and warnings in the response.

What protocol is used for communication between the Azure Cognitive Search and a custom skill?

For communication between Azure Cognitive Search and a custom skill, HTTP protocol is used for making RESTful API requests and responses.

Leave a Reply

Your email address will not be published. Required fields are marked *