Skip to content

Commit

Permalink
QOL changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xEcho1337 committed Dec 3, 2024
1 parent 8820870 commit 64e52e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/main/java/net/echo/brain4j/utils/Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public static Vector of(double... data) {
return new Vector(data);
}

public static Vector random(int size) {
return new Vector(size).fill(Math::random);
}

public void set(int index, double value) {
data[index] = value;
}
Expand Down Expand Up @@ -101,16 +105,20 @@ public Vector convoluted(Vector other) {
return new Vector(result);
}

public void add(Vector other) {
public Vector add(Vector other) {
for (int i = 0; i < data.length; i++) {
data[i] += other.data[i];
}

return this;
}

public void scale(double value) {
public Vector scale(double value) {
for (int i = 0; i < data.length; i++) {
data[i] *= value;
}

return this;
}

public double[] toArray() {
Expand Down
6 changes: 1 addition & 5 deletions src/test/java/antiswear/ToxicCommentClassification.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ private static Map<String, Vector> loadVocab() {
for (String token : content) {
if (token.startsWith("[") || token.startsWith("##")) continue;

Vector embedding = new Vector(EMBEDDING_DIM);

embedding.fill(Math::random).scale(10);

vectors.put(token, embedding);
vectors.put(token, Vector.random(EMBEDDING_DIM).scale(10));
}
} catch (Exception e) {
e.printStackTrace(System.err);
Expand Down

0 comments on commit 64e52e1

Please sign in to comment.