ConvoKit Documentation

repository·master·Indexed 20 days ago

https://github.com/cornellnlp/convokit

A Python toolkit for extracting conversational features and analyzing social phenomena in dialogue. It provides a unified interface compatible with scikit-learn and includes tools for linguistic coordination, politeness strategies, the Expected Conversational Context Framework, hypergraph conversation representation, and the CRAFT neural model. The toolkit includes a wide array of built-in conversational datasets, such as the Cornell Movie-Dialogs, Parliament Question Time, and Supreme Court Oral Arguments corpora.

Tokens
60.5K
Snippets
163
Records
267
Agent score
69%

What's inside ConvoKit

  1. Overview of ConvoKit

    master
    ConvoKit is a toolkit designed to extract conversational features and analyze social phenomena in conversations. It provides a single unified interface inspired by (and compatible with) scikit-learn. The toolkit includes several large conversational datasets and scripts to demonstrate how to use its features on these datasets. It is designed for researchers and developers interested in computational linguistics and social science analysis of dialogue.
  2. Overview of the ConvoKit GenAI module

    master

    The GenAI module provides a unified interface for integrating Large Language Models (LLMs) into ConvoKit conversational analysis workflows. It abstracts the differences between various LLM providers (like OpenAI GPT and Google Gemini) into a consistent interface, handling API key management and response formatting.

    Key components include:

    • LLMClient: The abstract base class defining the interface for all clients.
    • LLMResponse: A unified wrapper that standardizes outputs from different providers.
    • Factory Pattern: A factory function used to instantiate the appropriate client.
    • GenAIConfigManager: Manages API keys and provider-specific configurations.
    • LLMPromptTransformer: A ConvoKit transformer that applies custom prompts to corpus objects (utterances, conversations, speakers, or the entire corpus).
  3. Compute Politeness Strategies features

    master

    The politenessStrategies module allows you to extract politeness features and markers from conversations. It currently supports three distinct strategy collections across two languages:

    • politeness_api: English politeness strategies based on the computational approach described in A computational approach to politeness with application to social factors.
    • politeness_local: English politeness strategies realized through local markers, as used in Facilitating the Communication of Politeness through Fine-Grained Paraphrasing.
    • politeness_cscw_zh: Chinese politeness strategies adapted from Studying Politeness across Cultures using English Twitter and Mandarin Weibo.

    You can use these features to analyze conversational dynamics, such as understanding the misuse of politeness in 'conversations gone awry' or assessing how politeness markers behave in machine-translated text.

  4. Use the Expected Context Framework

    master

    The Expected Context Framework implementation in ConvoKit allows you to model and analyze conversational context. It provides several components to transform conversations and handle different context choices:

    • ExpectedContextModelTransformer: The basic transformer for implementing the framework.
    • DualContextWrapper: A wrapper designed to handle two distinct choices of conversational context.
    • ExpectedContextModelPipeline: A wrapper pipeline for managing the expected context model.
    • DualContextPipeline: A wrapper pipeline specifically for dual context scenarios.

    For practical implementations, refer to the following demonstration patterns:

    • Characterizing question types (e.g., in British parliamentary periods).
    • Exploring dialog acts (e.g., using the Switchboard corpus) with either the basic transformer or the DualContextWrapper.
    • Examining Wikipedia talk page discussions.
    • Computing utterance orientation (e.g., in US Supreme Court contexts).
  5. Navigate the Corpus class hierarchy

    master

    The data model follows a specific hierarchy where each component is identified by a unique ID (any arbitrary string):

    • Corpus: The top-level container holding conversations.
    • Conversation: A grouping of one or more utterances.
    • Utterance: An individual piece of text spoken by a participant. Each utterance stores its text and timestamp.
    • Speaker: The entity that authored an utterance. A single Speaker can participate in multiple Conversations.

    Relationships:

    • Corpus $\rightarrow$ Conversation $\rightarrow$ Utterance $\rightarrow$ Speaker.
  6. Model default configurations for Transformer Forecasters

    master

    If you do not provide a config object, the following default hyperparameters are used based on the model class:

    TransformerEncoderModel

    • per_device_batch_size=4
    • gradient_accumulation_steps=1
    • num_train_epochs=1
    • learning_rate=6.7e-6

    TransformerDecoderModel

    • per_device_batch_size=2
    • gradient_accumulation_steps=32
    • num_train_epochs=1
    • learning_rate=1e-4
  7. Use LLMPromptTransformer for corpus analysis

    master

    The LLMPromptTransformer is a ConvoKit transformer designed to apply custom LLM prompts to different levels of a corpus. You can target:

    • Utterances
    • Conversations
    • Speakers
    • The entire corpus

    It allows for fine-grained control over how data is formatted before being sent to the LLM and determines where the resulting analysis is stored within the ConvoKit objects.

  8. Use Summary of Conversation Dynamics (SCD) Transformer

    master

    SCD (Summary of Conversation Dynamics) is a ConvoKit Transformer that generates structured representations of conversational dynamics from transcripts. It produces two types of outputs:

    1. Summary of Conversation Dynamics (SCD): A high-level summary describing the overall dynamics within a conversation.
    2. Sequence of Patterns (SoP): A structured sequence of interaction patterns extracted from the SCD, used for comparing conversational dynamics.

    Prerequisite: LLM Setup SCD computation requires access to a Large Language Model (LLM). Before using the SCD Transformer, you must configure an LLM using the convokit.genai module. It is recommended to set up your GenAI models in that module first to ensure the SCD Transformer can successfully call the required model APIs.

  9. Understand Corpus components: Conversations, Utterances, and Speakers

    master

    A Corpus is composed of three primary interconnected components:

    1. Conversations: A sequence of Utterances.
    2. Utterances: Individual units of speech/text, each made by a Speaker and belonging to a Conversation.
    3. Speakers: The entities making the Utterances.

    Data Structure

    Each component contains:

    • Primary data fields: Core information like id, text, timestamp, and reply_to (for Utterances).
    • Metadata attributes: Additional features or labels (e.g., Reddit scores, speaker demographics) accessible via the .meta attribute.
    # Inspecting an utterance's primary fields and metadata
    utt = corpus.random_utterance()
    print(utt.id)
    print(utt.text)
    print(utt.meta['subreddit'])
  10. Choose a storage backend: Native Python vs MongoDB

    master

    ConvoKit offers two backend options for data handling:

    • Native Python Backend (Default): Keeps all data in memory during runtime. This is suitable for most use cases and requires no additional setup.
    • MongoDB Backend: Recommended for low-memory environments or real-time applications. This requires additional setup and configuration.
  11. Implement custom forecasting models using ForecasterModel

    master

    ConvoKit provides a ForecasterModel base class that can be subclassed to implement various forecasting architectures. To add a new model to the ConvoKit ecosystem (and potentially the official leaderboard), you should create a new subclass of ForecasterModel implementing the required forecasting logic.

    Available model types include:

    • DecisionPolicy
    • CRAFTModel
    • TransformerEncoderBasedModel
    • TransformerDecoderBasedModel

    To include a new model in the project's performance leaderboard, you must provide the ForecasterModel class and a version of the Run Transformer Fine-tuned Models.ipynb notebook that generates the corresponding leaderboard line.

  12. Use the Expected Conversational Context Framework

    master

    The Expected Conversational Context Framework allows you to characterize conversational dynamics using specific models. Key tools include:

    • ExpectedContextModelTransformer: Used for exploring dialog acts (e.g., in the Switchboard corpus).
    • DualContextWrapper: An alternative wrapper for exploring context.

    Common applications demonstrated in the repository:

    • Deriving question types in British parliamentary sessions.
    • Examining Wikipedia talk page discussions.
    • Computing the orientation of justice utterances in the US Supreme Court.
    # Example usage patterns:
    # Using ExpectedContextModelTransformer: https://github.com/CornellNLP/ConvoKit/blob/master/convokit/expected_context_framework/demos/switchboard_exploration_demo.ipynb
    # Using DualContextWrapper: https://github.com/CornellNLP/ConvoKit/blob/master/convokit/expected_context_framework/demos/switchboard_exploration_dual_demo.ipynb