DirectML Natural Language Processing (NLP) Samples

Accelerate Your NLP Workloads with DirectML

Explore powerful examples showcasing how to leverage DirectML for cutting-edge Natural Language Processing tasks on Windows.

Transformer Inference

High-Performance Text Generation

Implement and optimize Transformer models for tasks like text summarization, translation, and question answering using DirectML.

// Example snippet (conceptual) winrt::Microsoft::AI::DirectML::DMLDevice device = ...; auto transformerModel = winrt::Microsoft::AI::DirectML::Graph::LoadModel(L"path/to/transformer.onnx"); auto inputTensor = winrt::Microsoft::AI::DirectML::Tensor::CreateFromBuffer(device, DML_TENSOR_DATA_TYPE_FLOAT32, {1, 128}, inputBuffer); auto outputTensor = device.ExecuteGraph(transformerModel, {inputTensor});
Sentiment Analysis

Real-time Sentiment Detection

Utilize DirectML with models like BERT or RoBERTa to analyze the sentiment of text with low latency, ideal for real-time applications.

// Example snippet (conceptual) winrt::Microsoft::AI::DirectML::DMLCompiledOperator compiledOperator = ...; winrt::Microsoft::AI::DirectML::DMLOperatorOperatorDesc operatorDesc = ...; auto graph = winrt::Microsoft::AI::DirectML::Graph::CreateGraph(device, {operatorDesc}); auto inferenceSession = winrt::Microsoft::AI::DirectML::InferenceSession::Create(device, graph); auto results = inferenceSession.ProcessInput({textTensor});
Named Entity Recognition (NER)

Extract Key Information

Discover how to efficiently identify and categorize named entities (people, organizations, locations) in text using DirectML-accelerated models.

// Example snippet (conceptual) winrt::Microsoft::AI::DirectML::DMLBindingProperties properties = ...; auto descriptorHeap = device.CreateDescriptorHeap(properties.DescriptorCount); auto commandList = device.CreateCommandList(); commandList.AddOperator(nerOperator); commandList.Close(); device.Submit(commandList);
Custom Model Integration

Bring Your Own Models

Learn the steps to integrate custom NLP models, trained with popular frameworks, into your DirectML applications for optimized performance.

// Example snippet (conceptual) winrt::Microsoft::AI::DirectML::Graph::LoadGraph(device, L"path/to/your/model.xml"); // ... configure tensors and execute ...