### Quick Start: Entity Extraction Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Load a pre-trained model and extract entities from text. The model is automatically downloaded from HuggingFace. ```swift import GLiNER2Swift // Load model (downloads automatically from HuggingFace) let model = try await GLiNER2.fromPretrained("fastino/gliner2-base-v1") // Extract entities let text = "Tim Cook is CEO of Apple in Cupertino." let entities = try model.extractEntities( from: text, labels: ["person", "company", "location"] ) for entity in entities { print("\(entity.label): \(entity.text) [\(entity.start)-\(entity.end)]") } // Output: // person: Tim Cook [0-8] // company: Apple [23-28] // location: Cupertino [32-41] ``` -------------------------------- ### Load LoRA Adapter with GLiNER2Swift Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Demonstrates two methods for loading a GLiNER2Swift model with a LoRA adapter: a one-step process combining base model and adapter loading, and a two-step process loading the base model first, then attaching the adapter. Ensure the adapter path points to a valid LoRA adapter directory. ```swift let model = try await GLiNER2.fromPretrained( "fastino/gliner2-base-v1", adapterPath: "/path/to/adapter" ) ``` ```swift let model = try await GLiNER2.fromPretrained("fastino/gliner2-base-v1") try model.loadAdapter(from: "/path/to/adapter") ``` -------------------------------- ### API: Structured Extraction Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Create a schema for structured extraction, defining entities and classification tasks. ```swift let schema = model.createSchema() .entities(["person", "company"]) .classification(task: "sentiment", labels: ["positive", "negative"]) let result = try model.extract(from: text, schema: schema) ``` -------------------------------- ### Add Gliner2Swift to Package.swift Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Add the Gliner2Swift package to your project's Package.swift file to manage dependencies. ```swift dependencies: [ .package(url: "https://github.com/MacPaw/Gliner2Swift", branch: "main"), ] ``` -------------------------------- ### API: Entity Extraction Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Extract entities from a given text using specified labels. ```swift let entities = try model.extractEntities( from: "Your text here", labels: ["person", "organization", "location"] ) ``` -------------------------------- ### API: Text Classification Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Classify the sentiment of a given text into predefined categories. ```swift let classification = try model.classifyText( "Great product, highly recommend!", labels: ["positive", "negative", "neutral"] ) ``` -------------------------------- ### Structured Extraction Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Performs structured extraction from text based on a defined schema, which can include entities and text classification tasks. ```APIDOC ## Structured Extraction ### Description Performs structured extraction from text based on a defined schema, which can include entities and text classification tasks. ### Method Signature ```swift func extract(from text: String, schema: Schema) async throws -> ExtractionResult ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift let schema = model.createSchema() .entities(["person", "company"]) .classification(task: "sentiment", labels: ["positive", "negative"]) let result = try model.extract(from: text, schema: schema) ``` ### Response #### Success Response A `ExtractionResult` object containing the structured extraction results based on the provided schema. #### Response Example ```json { "entities": [ { "label": "person", "text": "Tim Cook", "start": 0, "end": 8 } ], "classification": { "sentiment": { "label": "positive", "score": 0.95 } } } ``` ``` -------------------------------- ### Entity Extraction Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Extracts entities from a given text based on a list of labels. This method is useful for Named Entity Recognition (NER) tasks. ```APIDOC ## Entity Extraction ### Description Extracts entities from a given text based on a list of labels. This method is useful for Named Entity Recognition (NER) tasks. ### Method Signature ```swift func extractEntities(from text: String, labels: [String]) async throws -> [Entity] ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift let entities = try model.extractEntities( from: "Your text here", labels: ["person", "organization", "location"] ) ``` ### Response #### Success Response An array of `Entity` objects, where each entity has a `label`, `text`, `start`, and `end` property. #### Response Example ```json [ { "label": "person", "text": "Tim Cook", "start": 0, "end": 8 } ] ``` ``` -------------------------------- ### Text Classification Source: https://github.com/macpaw/gliner2swift/blob/main/README.md Classifies a given text into one of the provided labels. This is useful for tasks like sentiment analysis or topic categorization. ```APIDOC ## Text Classification ### Description Classifies a given text into one of the provided labels. This is useful for tasks like sentiment analysis or topic categorization. ### Method Signature ```swift func classifyText(_ text: String, labels: [String]) async throws -> Classification ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift let classification = try model.classifyText( "Great product, highly recommend!", labels: ["positive", "negative", "neutral"] ) ``` ### Response #### Success Response A `Classification` object containing the predicted label and its confidence score. #### Response Example ```json { "label": "positive", "score": 0.95 } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.