hdallatorre commited on
Commit
1296232
1 Parent(s): 80953a2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +6 -3
README.md CHANGED
@@ -42,8 +42,8 @@ tokenizer = AutoTokenizer.from_pretrained("InstaDeepAI/nucleotide-transformer-2.
42
  model = AutoModelForMaskedLM.from_pretrained("InstaDeepAI/nucleotide-transformer-2.5b-1000g")
43
 
44
  # Create a dummy dna sequence and tokenize it
45
- sequences = ['ATTCTG' * 9]
46
- tokens_ids = tokenizer.batch_encode_plus(sequences, return_tensors="pt")["input_ids"]
47
 
48
  # Compute the embeddings
49
  attention_mask = tokens_ids != tokenizer.pad_token_id
@@ -59,8 +59,11 @@ embeddings = torch_outs['hidden_states'][-1].detach().numpy()
59
  print(f"Embeddings shape: {embeddings.shape}")
60
  print(f"Embeddings per token: {embeddings}")
61
 
 
 
 
62
  # Compute mean embeddings per sequence
63
- mean_sequence_embeddings = torch.sum(attention_mask.unsqueeze(-1)*embeddings, axis=-2)/torch.sum(attention_mask, axis=-1)
64
  print(f"Mean sequence embeddings: {mean_sequence_embeddings}")
65
  ```
66
 
 
42
  model = AutoModelForMaskedLM.from_pretrained("InstaDeepAI/nucleotide-transformer-2.5b-1000g")
43
 
44
  # Create a dummy dna sequence and tokenize it
45
+ sequences = ["ATTCCGATTCCGATTCCG", "ATTTCTCTCTCTCTCTGAGATCGATCGATCGAT"]
46
+ tokens_ids = tokenizer.batch_encode_plus(sequences, return_tensors="pt", padding="max_length", max_length = max_length)["input_ids"]
47
 
48
  # Compute the embeddings
49
  attention_mask = tokens_ids != tokenizer.pad_token_id
 
59
  print(f"Embeddings shape: {embeddings.shape}")
60
  print(f"Embeddings per token: {embeddings}")
61
 
62
+ # Add embed dimension axis
63
+ attention_mask = torch.unsqueeze(attention_mask, dim=-1)
64
+
65
  # Compute mean embeddings per sequence
66
+ mean_sequence_embeddings = torch.sum(attention_mask*embeddings, axis=-2)/torch.sum(attention_mask, axis=1)
67
  print(f"Mean sequence embeddings: {mean_sequence_embeddings}")
68
  ```
69