Downloads · 30 days
0
sohomn/stage4-identity-embeddings
stage4-identity-embeddings is a feature extraction model from sohomn. Use it when you need embeddings to search or compare text. It is set up for peft. The card lists the license as mit.
Part of the Trinetra multi-cloud threat detection pipeline (Group 24). Maps logically equivalent cloud identities from AWS, Azure, and GCP to nearby points in a shared 128-dimensional embedding space using contrastive…
Downloads · 30 days
0
Access
Public
Updated Apr 4, 2026
Repo size
15.2 MB
Likes
0
Public
Click a slice to open those files.
.safetensors14.2 MB · 82%
From the Hugging Face model README
Part of the Trinetra multi-cloud threat detection pipeline (Group 24). Maps logically equivalent cloud identities from AWS, Azure, and GCP to nearby points in a shared 128-dimensional embedding space using contrastive learning.
The same person has different account identifiers across cloud providers:
user_aliceuser_alice_azuser_alice_gcpWithout identity linking, a cross-cloud pivot attack — where stolen AWS credentials are reused on GCP — appears as two completely unrelated events to the downstream graph neural network. This model maps all three to nearby points so Stage 5's graph can connect them and Stage 6's RGCN can detect the pivot.
| Component | Detail |
|---|---|
| Base model | google/flan-t5-base (encoder only) |
| Fine-tuning | LoRA rank=16, alpha=32, target=q,k,v,o |
| Projection head | Linear(512→256→128) + ReLU + LayerNorm |
| Output dim | 128 (z_identity) |
| Training loss | Contrastive with margin=0.3 |
| Positive pairs | Same person, different cloud provider |
| Negative pairs | Different persons, any provider |
| Epochs | 50 × 40 steps |
| Hardware | Kaggle T4 x1 |
| File | Description |
|---|---|
adapter/ | LoRA adapter weights (flan-t5-base encoder) |
proj_head.pt | Projection head weights (512→128) |
config.json | Training configuration |
z_identity.parquet | Pre-computed embeddings for all 33 pipeline identities |
import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModel
from peft import PeftModel
from huggingface_hub import hf_hub_download
REPO = "sohomn/stage4-identity-embeddings"
BASE = "google/flan-t5-base"
tokenizer = AutoTokenizer.from_pretrained(REPO)
base = AutoModel.from_pretrained(BASE)
encoder = PeftModel.from_pretrained(base, REPO + "/adapter")
encoder.eval()
proj = nn.Sequential(
nn.Linear(512, 256), nn.ReLU(), nn.LayerNorm(256), nn.Linear(256, 128)
)
proj.load_state_dict(torch.load(
hf_hub_download(REPO, "proj_head.pt"), map_location="cpu"
))
proj.eval()
def embed(identity: str, provider: str) -> list:
text = f"identity: {identity} provider: {provider}"
inputs = tokenizer(text, return_tensors="pt", max_length=32,
truncation=True, padding=True)
with torch.no_grad():
out = encoder.encoder(**inputs)
mask = inputs["attention_mask"].unsqueeze(-1).float()
emb = (out.last_hidden_state * mask).sum(1) / mask.sum(1)
z = proj(emb)
z = F.normalize(z, dim=-1)
return z[0].tolist()
print(embed("user_alice", "AWS")) # 128-dim vector
print(embed("user_alice_az", "Azure")) # should be close to above
(128,) per identity, L2-normalised| Setting | Value |
|---|---|
| Identity registry | 11 persons × 3 providers = 33 identities |
| Positive pairs | 33 (same person, different cloud) |
| Negative pairs | sampled each batch |
| Effective batch | 32 (16 pos + 16 neg) |
| Best loss | see config.json |
| Seed | 42 |