Feature Extraction
MLX
Safetensors
bidirectional_pplx_qwen3
apple-silicon
sentence-similarity
contextual-embeddings
perplexity
qwen3
custom_code
Instructions to use agentmish/pplx-embed-context-v1-4b-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use agentmish/pplx-embed-context-v1-4b-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download agentmish/pplx-embed-context-v1-4b-mlx --local-dir pplx-embed-context-v1-4b-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Download pplx_mlx_convert/architecture.py from agentmish/pplx-embed-context-v1-4b-mlx: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/agentmish/pplx-embed-context-v1-4b-mlx/resolve/main/pplx_mlx_convert/architecture.py
- Command line
-
hf download hf://agentmish/pplx-embed-context-v1-4b-mlx/pplx_mlx_convert/architecture.py
-
curl -L -o architecture.py https://huggingface.co/agentmish/pplx-embed-context-v1-4b-mlx/resolve/main/pplx_mlx_convert/architecture.py
1.47 kB
| from typing import Any | |
| import mlx.core as mx | |
| from mlx_lm.models.qwen3 import ModelArgs, Qwen3Model | |
| SUPPORTED_MODEL_TYPE = "bidirectional_pplx_qwen3" | |
| def make_bidirectional_padding_mask(attention_mask: mx.array | None) -> mx.array | None: | |
| """Create a full-attention key padding mask from a tokenizer attention mask.""" | |
| if attention_mask is None: | |
| return None | |
| return attention_mask.astype(mx.bool_)[:, None, None, :] | |
| class PPLXQwen3Model(Qwen3Model): | |
| """Qwen3 encoder variant used by Perplexity contextual embedding models.""" | |
| def __call__( | |
| self, | |
| inputs: mx.array, | |
| attention_mask: mx.array | None = None, | |
| input_embeddings: mx.array | None = None, | |
| ) -> mx.array: | |
| if input_embeddings is not None: | |
| hidden_states = input_embeddings | |
| else: | |
| hidden_states = self.embed_tokens(inputs) | |
| mask = make_bidirectional_padding_mask(attention_mask) | |
| for layer in self.layers: | |
| hidden_states = layer(hidden_states, mask, None) | |
| return self.norm(hidden_states) | |
| def get_pplx_model_classes(config: dict[str, Any]) -> tuple[type[PPLXQwen3Model], type[ModelArgs]]: | |
| model_type = config.get("model_type") | |
| if model_type != SUPPORTED_MODEL_TYPE: | |
| msg = ( | |
| f"Unsupported Perplexity model type {model_type!r}; expected {SUPPORTED_MODEL_TYPE!r}." | |
| ) | |
| raise ValueError(msg) | |
| return PPLXQwen3Model, ModelArgs | |