Dependency Parsing Task¶
openaivec.task.nlp.dependency_parsing ¶
Dependency parsing task for OpenAI API.
This module provides a predefined task for dependency parsing that analyzes syntactic dependencies between words in sentences using OpenAI's language models.
Example
Basic usage with BatchResponses:
from openai import OpenAI
from openaivec.responses import BatchResponses
from openaivec.task import nlp
client = OpenAI()
analyzer = BatchResponses.of_task(
client=client,
model_name="gpt-4o-mini",
task=nlp.DEPENDENCY_PARSING
)
texts = ["The cat sat on the mat.", "She quickly ran to the store."]
analyses = analyzer.parse(texts)
for analysis in analyses:
print(f"Tokens: {analysis.tokens}")
print(f"Dependencies: {analysis.dependencies}")
print(f"Root: {analysis.root_word}")
With pandas integration:
import pandas as pd
from openaivec import pandas_ext # Required for .ai accessor
from openaivec.task import nlp
df = pd.DataFrame({"text": ["The cat sat on the mat.", "She quickly ran to the store."]})
df["parsing"] = df["text"].ai.task(nlp.DEPENDENCY_PARSING)
# Extract parsing components
extracted_df = df.ai.extract("parsing")
print(extracted_df[["text", "parsing_tokens", "parsing_root_word", "parsing_syntactic_structure"]])
Attributes:
Name | Type | Description |
---|---|---|
DEPENDENCY_PARSING |
PreparedTask
|
A prepared task instance configured for dependency parsing with temperature=0.0 and top_p=1.0 for deterministic output. |