object LinAlg
- Alphabetic
- By Inheritance
- LinAlg
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
argmax(scores: Array[Float]): Int
Gets the index with the highest score.
Gets the index with the highest score.
- scores
Array of Scores to max
- returns
Index of the highest score
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
avgPooling(flattenEmbeddings: Array[Float], attentionMask: Array[Array[Long]], shape: Array[Long]): DenseMatrix[Float]
Performs average pooling on embeddings using an attention mask.
Performs average pooling on embeddings using an attention mask.
This method takes flattened embeddings, an attention mask, and the shape of the embeddings, and computes the average pooling. The pooling is done by grouping the embeddings based on the attention mask and computing the weighted sum of these groups. The result is normalized by the total weight of the attention mask.
- flattenEmbeddings
Array of flattened embeddings
- attentionMask
2D Array representing the attention mask
- shape
Array representing the shape of the embeddings (dimensions)
- returns
A DenseMatrix of floats representing the average pooled embeddings
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
clsAvgPooling(embeddings: Array[Array[Array[Float]]], attentionMask: Array[Array[Long]]): Array[Array[Float]]
Creates pooled embeddings by averaging the embeddings of the CLS token and the average embedding the sequence.
Creates pooled embeddings by averaging the embeddings of the CLS token and the average embedding the sequence.
- embeddings
Embeddings in shape (batchSize, sequenceLength, embeddingDim)
- attentionMask
Attention mask in shape (batchSize, sequenceLength)
- returns
The pooled embeddings in shape (batchSize, embeddingDim)
-
def
clsPooling(embeddings: Array[Array[Array[Float]]], attentionMask: Array[Array[Long]]): Array[Array[Float]]
Creates pooled embeddings by using the CLS token as the representative embedding of the sequence.
Creates pooled embeddings by using the CLS token as the representative embedding of the sequence.
- embeddings
Embeddings in shape (batchSize, sequenceLength, embeddingDim)
- attentionMask
Attention mask in shape (batchSize, sequenceLength)
- returns
The pooled embeddings in shape (batchSize, embeddingDim)
-
def
denseMatrixToArray(matrix: DenseMatrix[Float]): Array[Array[Float]]
Converts a DenseMatrix to a 2D array of floats.
Converts a DenseMatrix to a 2D array of floats.
This method is used to transform a DenseMatrix[Float] into a two-dimensional array. It iterates over the rows and columns of the DenseMatrix, copying each element into the corresponding position in the newly created 2D array.
- matrix
DenseMatrix[Float] that needs to be converted to a 2D array
- returns
An 2D array representing the same data as the input DenseMatrix
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
l2Normalize(embeddings: DenseMatrix[Float]): DenseMatrix[Float]
Normalizes each row of a DenseMatrix using the L2 norm.
Normalizes each row of a DenseMatrix using the L2 norm.
This method applies L2 normalization to the embeddings. It first computes the L2 norm for each row (embedding) in the input matrix. Then, it creates a matrix where each row is the computed norms vector, ensuring the dimensions match the input embeddings. Finally, it normalizes each row in the embeddings by dividing by the corresponding L2 norm.
The result is a DenseMatrix where each row (embedding) is L2 normalized, ensuring that embeddings have a consistent scale for further processing.
- embeddings
DenseMatrix[Float] representing the embeddings to be normalized
- returns
DenseMatrix[Float] where each row is an L2 normalized version of the corresponding row in the input matrix
-
def
lastPooling(embeddings: Array[Array[Array[Float]]], attentionMask: Array[Array[Long]]): Array[Array[Float]]
Creates pooled embeddings by taking the last token embedding of the sequence.
Creates pooled embeddings by taking the last token embedding of the sequence. Assumes right padding.
- embeddings
Embeddings in shape (batchSize, sequenceLength, embeddingDim)
- attentionMask
Attention mask in shape (batchSize, sequenceLength)
- returns
The pooled embeddings in shape (batchSize, embeddingDim)
- def lpNormalizeArray(array: Array[Float], p: Int = 2): Array[Float]
-
def
maxPooling(embeddings: Array[Array[Array[Float]]], attentionMask: Array[Array[Long]]): Array[Array[Float]]
Creates pooled embeddings by taking the maximum of the embedding features along the sequence.
Creates pooled embeddings by taking the maximum of the embedding features along the sequence.
- embeddings
Embeddings in shape (batchSize, sequenceLength, embeddingDim)
- returns
A 2D array representing the pooled embeddings
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
softmax(logitValues: Array[Float]): Array[Float]
Calculates softmax probabilities for an array of logits.
Calculates softmax probabilities for an array of logits.
- logitValues
Predicted raw logits
- returns
Probabilities for each class
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
tokenPooling(embeddings: Array[Array[Array[Float]]], index: Int): Array[Array[Float]]
Creates pooled embeddings by selecting the token at the index position.
Creates pooled embeddings by selecting the token at the index position.
- embeddings
Embeddings in shape (batchSize, sequenceLength, embeddingDim)
- index
Index Position to select for each sequence in the batch
- returns
A 2D array representing the pooled embeddings
-
def
tokenPooling(embeddings: Array[Array[Array[Float]]], indexes: Array[Int]): Array[Array[Float]]
Creates pooled embeddings by selecting the token at the index position.
Creates pooled embeddings by selecting the token at the index position.
- embeddings
Embeddings in shape (batchSize, sequenceLength, embeddingDim)
- indexes
Array of Index Positions to select for each sequence in the batch
- returns
A 2D array representing the pooled embeddings
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- object implicits