Skip to content

Implement Natural Language Processing Solutions - Q&A

This document contains comprehensive questions and answers for the Implement Natural Language Processing Solutions domain of the AI-102 exam.


Section 1: Azure AI Language Service Basics

Q1.1: What is Azure AI Language Service, and what capabilities does it provide?

Answer: Azure AI Language Service is a cloud-based service providing natural language processing capabilities. Key features include:

  1. Text Analytics:

    • Sentiment analysis
    • Key phrase extraction
    • Named entity recognition (NER)
    • Entity linking
    • Language detection
  2. Language Understanding (LUIS):

    • Intent recognition
    • Entity extraction
    • Custom language models
    • Conversational AI support
  3. Question Answering:

    • Knowledge base Q&A
    • Conversational Q&A
    • Multi-turn conversations
    • Context-aware responses
  4. Text Summarization:

    • Abstractive summarization
    • Extractive summarization
    • Multi-document summarization
    • Custom length summaries
  5. Text Translation:

    • Multi-language translation
    • Language detection
    • Custom translation models
    • Batch translation
  6. Conversational Language Understanding (CLU):

    • Multi-intent recognition
    • Named entity recognition
    • Orchestration workflows
    • Azure Bot Framework integration

Detailed Explanation: Azure AI Language Service consolidates multiple NLP capabilities into a unified service, providing text analysis, understanding, translation, and conversational capabilities for building intelligent applications.

Use Cases:

  • Customer feedback analysis
  • Content moderation
  • Chatbot development
  • Document understanding
  • Language translation
  • Knowledge base Q&A
  • Text summarization

Service Tiers:

  • Free Tier (F0): Limited transactions per month
  • Standard Tier (S): Pay-as-you-go pricing
  • Multi-Service Subscription: Consolidated billing

Documentation Links:


Q1.2: How do you implement sentiment analysis using Azure AI Language Service?

Answer: Implement sentiment analysis:

  1. Setup Language Client:

    python
    from azure.ai.textanalytics import TextAnalyticsClient
    from azure.core.credentials import AzureKeyCredential
    
    client = TextAnalyticsClient(
        endpoint=endpoint,
        credential=AzureKeyCredential(api_key)
    )
  2. Analyze Sentiment:

    python
    # Single document
    documents = ["I love this product! It's amazing."]
    
    response = client.analyze_sentiment(
        documents=documents,
        language="en"
    )
    
    for document_result in response:
        print(f"Sentiment: {document_result.sentiment}")
        print(f"Confidence: {document_result.confidence_scores}")
        # Positive: 0.95, Neutral: 0.02, Negative: 0.03
    
    # Multiple documents
    documents = [
        "Great service!",
        "The product is okay.",
        "Terrible experience."
    ]
    
    response = client.analyze_sentiment(
        documents=documents,
        language="en"
    )
  3. Sentiment with Opinion Mining:

    python
    response = client.analyze_sentiment(
        documents=["The hotel was great but the food was terrible."],
        language="en",
        include_opinion_mining=True  # Aspect-level sentiment
    )
    
    for document_result in response:
        for sentence in document_result.sentences:
            for mined_opinion in sentence.mined_opinions:
                aspect = mined_opinion.aspect
                print(f"Aspect: {aspect.text}, Sentiment: {aspect.sentiment}")
                for opinion in mined_opinion.opinions:
                    print(f"Opinion: {opinion.text}")

Detailed Explanation: Sentiment analysis evaluates text to determine emotional tone (positive, negative, neutral) and provides confidence scores. Opinion mining enables aspect-level sentiment analysis.

Sentiment Types:

  • Positive: Positive sentiment
  • Negative: Negative sentiment
  • Neutral: Neutral sentiment
  • Mixed: Both positive and negative sentiments

Sentiment Confidence Scores:

  • Provides probabilities for each sentiment
  • Sum to 1.0
  • Higher scores indicate higher confidence
  • Example: {"positive": 0.95, "neutral": 0.02, "negative": 0.03}

Opinion Mining:

  • Aspect-level sentiment analysis
  • Identifies specific aspects/aspects in text
  • Provides sentiment for each aspect
  • Useful for product reviews and feedback

Supported Languages:

  • English, Spanish, French, German, Italian, Portuguese
  • Chinese (Simplified and Traditional)
  • Japanese, Korean
  • Arabic, Russian
  • And many more (120+ languages)

Best Practices:

  • Specify language when known (improves accuracy)
  • Use auto-detection for unknown languages
  • Batch multiple documents (more efficient)
  • Handle errors gracefully
  • Cache results when appropriate

Use Cases:

  • Customer feedback analysis
  • Social media monitoring
  • Review analysis
  • Survey response analysis
  • Customer support prioritization

Documentation Links:


Q1.3: How do you extract key phrases and named entities from text?

Answer: Extract key phrases and named entities:

  1. Extract Key Phrases:

    python
    documents = [
        "Azure AI Language Service provides natural language processing capabilities."
    ]
    
    response = client.extract_key_phrases(
        documents=documents,
        language="en"
    )
    
    for document_result in response:
        print("Key phrases:")
        for phrase in document_result.key_phrases:
            print(f"  - {phrase}")
    # Output: Azure AI Language Service, natural language processing capabilities
  2. Recognize Named Entities:

    python
    documents = [
        "Microsoft was founded by Bill Gates in 1975 in Redmond, Washington."
    ]
    
    response = client.recognize_entities(
        documents=documents,
        language="en"
    )
    
    for document_result in response:
        for entity in document_result.entities:
            print(f"Entity: {entity.text}")
            print(f"Category: {entity.category}")
            print(f"Subcategory: {entity.subcategory}")
            print(f"Confidence: {entity.confidence_score}")
  3. Entity Linking:

    python
    documents = [
        "Microsoft Azure is a cloud computing platform."
    ]
    
    response = client.recognize_linked_entities(
        documents=documents,
        language="en"
    )
    
    for document_result in response:
        for entity in document_result.entities:
            print(f"Name: {entity.name}")
            print(f"URL: {entity.url}")
            print(f"Data source: {entity.data_source}")

Detailed Explanation: Key phrase extraction identifies important topics and concepts, while named entity recognition identifies people, places, organizations, and other entities. Entity linking connects entities to knowledge bases.

Key Phrase Extraction:

  • Identifies important concepts and topics
  • Useful for document summarization
  • Enables topic modeling
  • Supports search and indexing

Named Entity Categories:

  • Person: Names of people
  • Location: Places, cities, countries
  • Organization: Companies, institutions
  • Quantity: Numbers, measurements
  • DateTime: Dates, times
  • Event: Named events
  • Product: Product names
  • Skill: Skills and abilities
  • And more categories

Entity Linking:

  • Links entities to Wikipedia knowledge base
  • Provides additional context
  • Enables knowledge graph integration
  • Supports disambiguation

Entity Recognition Features:

  • Multi-word entity detection
  • Confidence scores
  • Entity categories and subcategories
  • Text spans and positions

Best Practices:

  • Use appropriate entity recognition models
  • Combine with other NLP capabilities
  • Handle multiple entities per document
  • Consider entity linking for disambiguation

Documentation Links:


Section 2: Language Understanding (LUIS)

Q2.1: What is Language Understanding (LUIS), and how is it used?

Answer: Language Understanding (LUIS) is a cloud-based service for building custom language understanding models that can:

  • Recognize user intent from natural language
  • Extract entities from utterances
  • Build conversational AI applications
  • Integrate with Azure Bot Framework

How LUIS Works:

  1. Intent Recognition: Identifies what the user wants
  2. Entity Extraction: Extracts relevant information
  3. Utterance Understanding: Interprets natural language input

LUIS Concepts:

  • Intent: User's goal or purpose (e.g., "BookFlight", "GetWeather")
  • Entity: Information extracted from text (e.g., location, date, person)
  • Utterance: Example input text that users might say
  • App: Container for intents, entities, and utterances
  • Training: Teaching the model with examples
  • Prediction: Using the model to understand new input

Detailed Explanation: LUIS enables building custom language understanding models without deep machine learning expertise, making it accessible for developers to create conversational AI applications.

LUIS Workflow:

  1. Create LUIS App: Define intents and entities
  2. Add Utterances: Provide example user inputs
  3. Label Entities: Mark entities in utterances
  4. Train Model: Train with labeled examples
  5. Test Model: Test with sample inputs
  6. Publish: Deploy model for use
  7. Predict: Use model in applications

Use Cases:

  • Chatbots and virtual assistants
  • Voice applications
  • Command and control systems
  • Customer service automation
  • IoT device control

Documentation Links:


Q2.2: How do you create and train a LUIS application?

Answer: Create and train a LUIS application:

  1. Create LUIS App:

    python
    from azure.cognitiveservices.language.luis.authoring import LUISAuthoringClient
    from msrest.authentication import CognitiveServicesCredentials
    
    authoring_client = LUISAuthoringClient(
        endpoint=authoring_endpoint,
        credentials=CognitiveServicesCredentials(authoring_key)
    )
    
    # Create app
    app = authoring_client.apps.add({
        "name": "My LUIS App",
        "description": "Custom language understanding app",
        "culture": "en-us",
        "domain": "None",
        "initial_version_id": "0.1"
    })
  2. Create Intent:

    python
    intent = authoring_client.model.add_intent(
        app_id=app_id,
        version_id="0.1",
        name="BookFlight"
    )
  3. Create Entity:

    python
    # Simple entity
    entity = authoring_client.model.add_entity(
        app_id=app_id,
        version_id="0.1",
        name="Location"
    )
    
    # Prebuilt entity (datetimeV2)
    prebuilt_entity = authoring_client.model.add_prebuilt(
        app_id=app_id,
        version_id="0.1",
        prebuilt_extractor_names=["datetimeV2"]
    )
    
    # List entity (airport codes)
    list_entity = authoring_client.model.add_list_entity(
        app_id=app_id,
        version_id="0.1",
        name="AirportCodes",
        sub_lists=[
            {"canonical_form": "SEA", "list": ["Seattle", "SeaTac"]},
            {"canonical_form": "LAX", "list": ["Los Angeles", "LAX Airport"]}
        ]
    )
  4. Add Utterances:

    python
    utterances = [
        {
            "text": "Book a flight to Seattle",
            "intent_name": "BookFlight",
            "entity_labels": [
                {
                    "entity_name": "Location",
                    "start_char_index": 20,
                    "end_char_index": 27
                }
            ]
        },
        {
            "text": "I want to travel to New York on March 15",
            "intent_name": "BookFlight",
            "entity_labels": [
                {"entity_name": "Location", "start_char_index": 20, "end_char_index": 27},
                {"entity_name": "datetimeV2", "start_char_index": 31, "end_char_index": 40}
            ]
        }
    ]
    
    authoring_client.examples.batch(
        app_id=app_id,
        version_id="0.1",
        example_label_objects=utterances
    )
  5. Train Model:

    python
    authoring_client.train.train_version(
        app_id=app_id,
        version_id="0.1"
    )
    
    # Wait for training
    while True:
        status = authoring_client.train.get_status(app_id, "0.1")
        if all(m.details.status == "Success" for m in status):
            break
        time.sleep(1)
  6. Publish:

    python
    publish_result = authoring_client.apps.publish(
        app_id=app_id,
        application_version="0.1",
        is_staging=False
    )
  7. Predict:

    python
    from azure.cognitiveservices.language.luis.runtime import LUISRuntimeClient
    
    runtime_client = LUISRuntimeClient(
        endpoint=prediction_endpoint,
        credentials=CognitiveServicesCredentials(prediction_key)
    )
    
    prediction = runtime_client.prediction.get_slot_prediction(
        app_id=app_id,
        slot_name="production",
        prediction_request={
            "query": "Book a flight to Seattle tomorrow"
        }
    )
    
    print(f"Intent: {prediction.prediction.top_intent}")
    print(f"Score: {prediction.prediction.intents[prediction.prediction.top_intent].score}")
    for entity in prediction.prediction.entities:
        print(f"Entity: {entity.entity_name}, Value: {entity.values}")

Detailed Explanation: Creating a LUIS application involves defining intents and entities, providing training examples (utterances), training the model, and publishing it for use in applications.

Entity Types:

  • Simple Entity: Free-form text entity
  • Prebuilt Entity: Built-in entities (datetimeV2, number, geographyV2, etc.)
  • List Entity: Closed list of values with synonyms
  • Regular Expression Entity: Pattern-based extraction
  • Composite Entity: Combination of multiple entities
  • Machine Learning Entity: Learned entity from examples

Training Best Practices:

  • Diverse Utterances: Provide varied examples
  • Entity Labeling: Accurately label all entities
  • Negative Examples: Add None intent examples
  • Sufficient Examples: Minimum 5-10 utterances per intent
  • Regular Updates: Continuously improve with new examples

Versioning:

  • Create versions for major changes
  • Test new versions before publishing
  • Keep previous versions for rollback
  • Version naming (e.g., "0.1", "0.2", "1.0")

Documentation Links:


Section 3: Azure AI Speech Service

Q3.1: What is Azure AI Speech Service, and what capabilities does it provide?

Answer: Azure AI Speech Service provides speech recognition, synthesis, and translation capabilities. Key features include:

  1. Speech-to-Text (STT):

    • Real-time speech recognition
    • Batch transcription
    • Custom speech models
    • Multi-language support
    • Speaker diarization
  2. Text-to-Speech (TTS):

    • Natural-sounding voice synthesis
    • Neural voices
    • Custom voices
    • SSML support
    • Multiple voice styles
  3. Speech Translation:

    • Real-time translation
    • Batch translation
    • Multi-language support
    • Direct speech-to-speech translation
  4. Speaker Recognition:

    • Speaker identification
    • Speaker verification
    • Speaker diarization
  5. Conversation Transcription:

    • Multi-speaker transcription
    • Speaker separation
    • Real-time transcription

Detailed Explanation: Azure Speech Service enables building applications with speech capabilities, supporting natural human-computer interaction through voice.

Use Cases:

  • Voice assistants
  • Call center transcription
  • Real-time captioning
  • Voice commands
  • Translation apps
  • Accessibility features
  • Voice navigation

Speech Models:

  • Universal Models: Pre-trained, general-purpose
  • Custom Models: Domain-specific training
  • Neural Voices: High-quality TTS voices
  • Standard Voices: Traditional TTS voices

Supported Languages:

  • 100+ languages for speech recognition
  • 80+ languages for translation
  • 200+ neural voices
  • Multiple dialects

Documentation Links:


Q3.2: How do you implement speech-to-text (speech recognition)?

Answer: Implement speech-to-text:

  1. Setup Speech Client:

    python
    import azure.cognitiveservices.speech as speechsdk
    
    speech_config = speechsdk.SpeechConfig(
        subscription=speech_key,
        region=speech_region
    )
  2. Basic Speech Recognition:

    python
    # Configure recognition
    speech_config.speech_recognition_language = "en-US"
    
    # Create recognizer
    audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
    speech_recognizer = speechsdk.SpeechRecognizer(
        speech_config=speech_config,
        audio_config=audio_config
    )
    
    # Recognize once
    result = speech_recognizer.recognize_once()
    
    if result.reason == speechsdk.ResultReason.RecognizedSpeech:
        print(f"Recognized: {result.text}")
    elif result.reason == speechsdk.ResultReason.NoMatch:
        print(f"No speech recognized: {result.no_match_details}")
    elif result.reason == speechsdk.ResultReason.Canceled:
        print(f"Canceled: {result.cancellation_details}")
  3. Continuous Recognition:

    python
    def recognized_cb(evt):
        print(f"Recognized: {evt.result.text}")
    
    def canceled_cb(evt):
        print(f"Canceled: {evt}")
    
    speech_recognizer.recognized.connect(recognized_cb)
    speech_recognizer.canceled.connect(canceled_cb)
    
    speech_recognizer.start_continuous_recognition()
    
    # Stop when done
    speech_recognizer.stop_continuous_recognition()
  4. File-Based Recognition:

    python
    audio_config = speechsdk.audio.AudioConfig(filename="audio.wav")
    speech_recognizer = speechsdk.SpeechRecognizer(
        speech_config=speech_config,
        audio_config=audio_config
    )
    
    result = speech_recognizer.recognize_once()
  5. Custom Speech Model:

    python
    speech_config.speech_recognition_language = "en-US"
    speech_config.endpoint_id = "your-custom-endpoint-id"
    
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config)
  6. Batch Transcription:

    python
    import requests
    
    # Create transcription job
    headers = {
        "Ocp-Apim-Subscription-Key": speech_key,
        "Content-Type": "application/json"
    }
    
    body = {
        "contentUrls": ["https://example.com/audio.wav"],
        "properties": {
            "diarizationEnabled": True,
            "wordLevelTimestampsEnabled": True
        }
    }
    
    response = requests.post(
        f"https://{region}.cris.ai/api/speechtotext/v3.1/transcriptions",
        headers=headers,
        json=body
    )

Detailed Explanation: Speech-to-text converts spoken audio into text, supporting real-time and batch transcription with various customization options.

Recognition Modes:

  • Single Recognition: One-shot recognition
  • Continuous Recognition: Continuous streaming recognition
  • Conversation Transcription: Multi-speaker recognition
  • Batch Transcription: Asynchronous file processing

Recognition Features:

  • Language Detection: Auto-detect spoken language
  • Speaker Diarization: Separate multiple speakers
  • Word-Level Timestamps: Precise timing information
  • Profanity Filtering: Filter offensive content
  • Custom Models: Domain-specific recognition

Best Practices:

  • Specify language for better accuracy
  • Use appropriate audio format (WAV, MP3, etc.)
  • Handle audio quality issues
  • Implement error handling
  • Use custom models for domain-specific content

Documentation Links:


Q3.3: How do you implement text-to-speech (speech synthesis)?

Answer: Implement text-to-speech:

  1. Basic Text-to-Speech:

    python
    import azure.cognitiveservices.speech as speechsdk
    
    speech_config = speechsdk.SpeechConfig(
        subscription=speech_key,
        region=speech_region
    )
    
    # Configure voice
    speech_config.speech_synthesis_voice_name = "en-US-AriaNeural"
    
    # Create synthesizer
    synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
    
    # Synthesize text
    result = synthesizer.speak_text_async("Hello, this is a test.").get()
    
    if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
        print("Speech synthesized successfully")
    elif result.reason == speechsdk.ResultReason.Canceled:
        print(f"Error: {result.cancellation_details}")
  2. Using SSML (Speech Synthesis Markup Language):

    python
    ssml = """
    <speak version='1.0' xml:lang='en-US'>
        <voice name='en-US-AriaNeural'>
            <prosody rate='fast' pitch='high'>
                This is fast, high-pitched speech.
            </prosody>
        </voice>
    </speak>
    """
    
    result = synthesizer.speak_ssml_async(ssml).get()
  3. Save to File:

    python
    audio_config = speechsdk.audio.AudioOutputConfig(filename="output.wav")
    synthesizer = speechsdk.SpeechSynthesizer(
        speech_config=speech_config,
        audio_config=audio_config
    )
    
    result = synthesizer.speak_text_async("Hello, world!").get()
  4. Streaming Output:

    python
    def stream_cb(evt):
        audio_chunk = evt.audio_data
        # Process audio chunk
    
    synthesizer.synthesizing.connect(stream_cb)
    result = synthesizer.speak_text_async("Long text here...").get()
  5. Custom Voice:

    python
    speech_config.speech_synthesis_voice_name = "your-custom-voice"
    synthesizer = speechsdk.SpeechSynthesizer(speech_config)

Detailed Explanation: Text-to-speech converts text into natural-sounding speech, supporting various voices, styles, and languages with SSML for advanced control.

Voice Types:

  • Neural Voices: High-quality, natural-sounding voices
  • Standard Voices: Traditional synthesis voices
  • Custom Voices: Custom-trained voices

SSML Capabilities:

  • Voice Selection: Choose specific voices
  • Prosody Control: Rate, pitch, volume
  • Pronunciation: Phonetic pronunciation
  • Break: Pauses and breaks
  • Emphasis: Stress emphasis
  • Styles: Emotional styles (cheerful, sad, etc.)

SSML Example:

xml
<speak version='1.0' xml:lang='en-US'>
    <voice name='en-US-AriaNeural'>
        <mstts:express-as style='cheerful'>
            Hello! How are you?
        </mstts:express-as>
    </voice>
</speak>

Best Practices:

  • Choose appropriate voice for content
  • Use SSML for natural speech
  • Adjust prosody for clarity
  • Consider pronunciation for technical terms
  • Test with target audience

Documentation Links:


Q3.4: How do you implement speech translation?

Answer: Implement speech translation:

  1. Basic Speech Translation:

    python
    import azure.cognitiveservices.speech as speechsdk
    
    speech_config = speechsdk.SpeechConfig(
        subscription=speech_key,
        region=speech_region
    )
    
    # Configure translation
    speech_config.speech_recognition_language = "en-US"
    translation_config = speechsdk.translation.SpeechTranslationConfig(
        subscription=speech_key,
        region=speech_region,
        speech_recognition_language="en-US",
        target_languages=["fr", "es", "de"]
    )
    
    # Create translator
    audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
    translator = speechsdk.translation.TranslationRecognizer(
        translation_config=translation_config,
        audio_config=audio_config
    )
    
    # Translate
    result = translator.recognize_once()
    
    if result.reason == speechsdk.ResultReason.TranslatedSpeech:
        print(f"Original: {result.text}")
        for language, translation in result.translations.items():
            print(f"{language}: {translation}")
  2. Continuous Translation:

    python
    def recognized_cb(evt):
        print(f"Recognized: {evt.result.text}")
        for language, translation in evt.result.translations.items():
            print(f"{language}: {translation}")
    
    translator.recognized.connect(recognized_cb)
    translator.start_continuous_recognition()
  3. Synthesize Translation:

    python
    translation_config.voice_name = "fr-FR-DeniseNeural"
    translation_config.add_target_language("fr")
    
    # Translation will include synthesized audio
    result = translator.recognize_once()

Detailed Explanation: Speech translation recognizes speech in one language and translates it to target languages, supporting real-time translation scenarios.

Translation Features:

  • Multi-Language Targets: Translate to multiple languages simultaneously
  • Real-Time Translation: Stream translations as speech is recognized
  • Synthesized Output: Generate speech in target language
  • Language Detection: Auto-detect source language

Use Cases:

  • Real-time conversation translation
  • Presentation translation
  • Customer support translation
  • Language learning applications
  • International communication

Supported Languages:

  • 80+ languages for translation
  • Various language pairs
  • Neural translation models
  • Regional dialects

Documentation Links:


Section 4: Question Answering

Q4.1: What is Question Answering in Azure AI Language Service?

Answer: Question Answering (formerly QnA Maker) is a service that enables building question-and-answer knowledge bases that can:

  • Answer questions from a knowledge base
  • Support multi-turn conversations
  • Learn from user feedback
  • Integrate with chatbots

Key Features:

  1. Knowledge Base Creation:

    • Import from documents (PDF, Word, etc.)
    • Manual Q&A pairs
    • URLs and FAQs
    • Chit-chat support
  2. Multi-Turn Conversations:

    • Context-aware responses
    • Follow-up question handling
    • Conversation flow management
  3. Active Learning:

    • Suggests improvements from user queries
    • Learns from feedback
    • Continuously improves accuracy
  4. Integration:

    • Azure Bot Framework
    • REST API
    • SDKs for multiple languages

Detailed Explanation: Question Answering provides an easy way to create question-answer systems without deep AI expertise, ideal for FAQ bots, documentation assistants, and knowledge bases.

Question Answering Workflow:

  1. Create Knowledge Base: Define Q&A pairs or import documents
  2. Train: Train knowledge base
  3. Test: Test with sample questions
  4. Publish: Deploy for use
  5. Integrate: Use in applications (bots, APIs)

Use Cases:

  • FAQ chatbots
  • Documentation assistants
  • Customer support bots
  • Knowledge bases
  • Help desk automation

Documentation Links:


Q4.2: How do you create a Question Answering knowledge base?

Answer: Create a Question Answering knowledge base:

  1. Create Resource:

    • Create Language resource in Azure Portal
    • Note endpoint and key
  2. Create Knowledge Base (REST API):

    python
    import requests
    
    headers = {
        "Ocp-Apim-Subscription-Key": api_key,
        "Content-Type": "application/json"
    }
    
    # Create knowledge base
    body = {
        "name": "My Knowledge Base",
        "qnaList": [
            {
                "id": 1,
                "answer": "Azure AI Language Service provides natural language processing capabilities.",
                "source": "custom",
                "questions": ["What is Azure AI Language Service?"],
                "metadata": []
            },
            {
                "id": 2,
                "answer": "You can create a knowledge base using the REST API or Language Studio.",
                "source": "custom",
                "questions": ["How do I create a knowledge base?"],
                "metadata": []
            }
        ],
        "urls": [],
        "files": []
    }
    
    response = requests.post(
        f"{endpoint}/language/query-knowledgebases/projects/{project_name}/:import",
        headers=headers,
        json=body
    )
  3. Import from Documents:

    python
    # Upload document to Azure Storage
    # Import from storage
    body = {
        "metadata": {
            "ProjectName": project_name
        },
        "sources": [
            {
                "sourceUri": "https://storage.azure.com/document.pdf",
                "sourceKind": "file"
            }
        ]
    }
    
    response = requests.post(
        f"{endpoint}/language/query-knowledgebases/projects/{project_name}/:import",
        headers=headers,
        json=body
    )
  4. Deploy Knowledge Base:

    python
    deployment_name = "production"
    
    response = requests.put(
        f"{endpoint}/language/query-knowledgebases/projects/{project_name}/deployments/{deployment_name}",
        headers=headers
    )
  5. Query Knowledge Base:

    python
    query = {
        "question": "What is Azure AI Language Service?",
        "top": 3,
        "confidenceScoreThreshold": 0.5,
        "context": {
            "previousQnaId": None,
            "previousUserQuery": None
        }
    }
    
    response = requests.post(
        f"{endpoint}/language/query-knowledgebases/projects/{project_name}/deployments/{deployment_name}/:query",
        headers=headers,
        json=query
    )
    
    result = response.json()
    answers = result["answers"]
    for answer in answers:
        print(f"Answer: {answer['answer']}")
        print(f"Confidence: {answer['confidenceScore']}")

Detailed Explanation: Question Answering knowledge bases can be created manually, imported from documents, or built from FAQs and URLs, providing flexible knowledge source options.

Knowledge Base Sources:

  • Manual Q&A Pairs: Direct question-answer pairs
  • Documents: PDF, Word, TXT files
  • URLs: Web pages and FAQs
  • Structured Data: CSV and structured formats

Multi-Turn Conversations:

  • Maintain conversation context
  • Handle follow-up questions
  • Reference previous answers
  • Context-aware responses

Active Learning:

  • Suggests question variations
  • Identifies knowledge gaps
  • Learns from user queries
  • Improves over time

Best Practices:

  • Provide diverse question variations
  • Include context in answers
  • Organize knowledge logically
  • Regularly update knowledge base
  • Test with real user queries

Documentation Links:


Summary

This document covers key aspects of implementing natural language processing solutions, including Azure AI Language Service, LUIS, Speech Service, and Question Answering. Each topic is essential for success in the AI-102 exam and real-world NLP implementations.

Additional Study Resources

Released under the MIT License.