--- license: apache-2.0 base_model: knowledgator/gliner-relex-base-v1.0 pipeline_tag: token-classification library_name: openmed tags: - openmed - mlx - apple-silicon - swift - ios - zero-shot - relation-extraction - gliner-relex - medical - clinical --- # OpenMed GLiNER-Relex Base v1.0 MLX This is a public [OpenMed](https://github.com/maziyarpanahi/openmed) MLX artifact for zero-shot entity and relation extraction on Apple Silicon. It packages [`knowledgator/gliner-relex-base-v1.0`](https://huggingface.co/knowledgator/gliner-relex-base-v1.0) in the OpenMed MLX format so it can run locally in Python, macOS, and iOS apps through OpenMedKit. OpenMed is the main developer experience: - Website: [openmed.life](https://openmed.life) - GitHub: [github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed) - Python: `pip install "openmed[mlx]"` - Swift: add the OpenMed GitHub repository as a Swift Package and use `OpenMedKit` ## What This Model Does `OpenMed/gliner-relex-base-v1.0-mlx` performs experimental zero-shot relation extraction. You provide: - entity labels, such as `medication`, `condition`, `symptom`, or `procedure` - relation labels, such as `treats`, `causes`, `associated with`, or `contraindicated for` - input text The model returns extracted entities plus directed relation triples between entity pairs. Artifact metadata: - OpenMed MLX task: `zero-shot-relation-extraction` - OpenMed MLX family: `gliner-uni-encoder-token-relex` - Backbone: DeBERTa-v3 / `deberta-v2` config family - Max sequence length: `512` - Weight format: `weights.safetensors` - Runtime APIs: `GLiNERRelexMLXPipeline` in Python and `OpenMedRelationExtractor` in Swift - Runtime status: experimental ## Python Quick Start Install OpenMed with MLX support: ```bash pip install -U "openmed[mlx]" ``` Run relation extraction from the Hub snapshot: ```python from huggingface_hub import snapshot_download from openmed.mlx.inference import GLiNERRelexMLXPipeline model_path = snapshot_download("OpenMed/gliner-relex-base-v1.0-mlx") extractor = GLiNERRelexMLXPipeline(model_path) result = extractor.inference( "Aspirin was prescribed for headache after the patient reported migraine symptoms.", labels=["medication", "condition", "symptom"], relations=["treats", "associated with"], threshold=0.5, relation_threshold=0.9, ) print(result["entities"]) print(result["relations"]) ``` You can also load a local snapshot directory: ```python from openmed.mlx.inference import create_mlx_pipeline extractor = create_mlx_pipeline("/path/to/gliner-relex-base-v1.0-mlx") ``` ## Swift And iOS Quick Start Add OpenMedKit to your Xcode project: 1. In Xcode, choose `File > Add Package Dependencies`. 2. Paste `https://github.com/maziyarpanahi/openmed`. 3. Add the `OpenMedKit` package product to your app target. 4. Download this MLX artifact once, then reuse the cached local model for offline inference. Example: ```swift import OpenMedKit let modelURL = try await OpenMedModelStore.downloadMLXModel( repoID: "OpenMed/gliner-relex-base-v1.0-mlx" ) let extractor = try OpenMedRelationExtractor(modelDirectoryURL: modelURL) let result = try extractor.extract( "Aspirin was prescribed for headache after the patient reported migraine symptoms.", entityLabels: ["medication", "condition", "symptom"], relationLabels: ["treats", "associated with"], threshold: 0.5, relationThreshold: 0.9 ) for entity in result.entities { print(entity.label, entity.text, entity.score) } for relation in result.relations { print(relation.head.text, relation.label, relation.tail.text, relation.score) } ``` Notes for Apple apps: - MLX inference runs on Apple Silicon and supported Apple devices. - The iOS Simulator is not the acceptance target for MLX inference; test on a physical iPhone or iPad. - After the first model download, inference is local and does not require a server. ## Prompt Format The artifact includes OpenMed prompt-packing metadata so Python and Swift build the same input sequence: ```json { "kind": "gliner-relex", "entity_token": "<>", "relation_token": "<>", "separator_token": "<>", "class_token_index": 128001, "rel_token_index": 128003, "embed_marker_token": true, "split_mode": "words" } ``` ## Practical Guidance - Start with a conservative `relation_threshold`, such as `0.9`, for cleaner demos. - Use concise labels. For example, prefer `medication` over a long natural-language phrase. - Tune `threshold` and `relation_threshold` separately because entity recall and relation precision behave differently. - Keep inputs under the artifact's `512` token context window or chunk text before inference. - Treat this runtime as experimental while OpenMed continues parity testing across Python MLX and Swift MLX. ## Credits - Base checkpoint: [`knowledgator/gliner-relex-base-v1.0`](https://huggingface.co/knowledgator/gliner-relex-base-v1.0) - OpenMed GitHub: [github.com/maziyarpanahi/openmed](https://github.com/maziyarpanahi/openmed) - OpenMed website: [openmed.life](https://openmed.life) - MLX packaging, Python runtime, and Swift runtime: OpenMed