Skip to content

Commit

Permalink
clean up sakana
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Oct 11, 2023
1 parent f281e4b commit 6f1923c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,37 @@ output = model(x)

```

- Fish School/Sakana is an all-new innovative approaches to machine learning that leverage the power of the Transformer model architecture. These systems are designed to mimic the behavior of a school of fish, where each fish represents an individual Transformer model. The goal is to optimize the performance of the entire school by learning from the best-performing fish.

```python
import torch
from swarms_torch.fish_school import Fish, FishSchool

# Create random source and target sequences
src = torch.randn(10, 32, 512)
tgt = torch.randn(10, 32, 512)

# Create random labels
labels = torch.randint(0, 512, (10, 32))

# Create a fish and train it on the random data
fish = Fish(512, 8, 6)
fish.train(src, tgt, labels)
print(fish.food) # Print the fish's food

# Create a fish school and optimize it on the random data
school = FishSchool(10, 512, 8, 6, 100)
school.forward(src, tgt, labels)
print(school.fish[0].food) # Print the first fish's food

```

# Documentation
- [Click here for documentation](https://swarmstorch.readthedocs.io/en/latest/swarms/)


# Todo
Here are 10 swarming neural network algorithms, with brief overviews, algorithmic pseudocode, and potential use cases for each:
10 swarming neural network algorithms, with brief overviews, algorithmic pseudocode, and potential use cases for each:

1. **Particle Swarm Optimization (PSO)**
- **Overview**: Simulates the social behavior of birds flocking or fish schooling. It adjusts trajectories of individual agents (particles) based on their own and their neighbors' best known positions.
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions playground/fish_school_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import torch
from swarms_torch.fish_school import Fish, FishSchool

# Create random source and target sequences
src = torch.randn(10, 32, 512)
tgt = torch.randn(10, 32, 512)

# Create random labels
labels = torch.randint(0, 512, (10, 32))

# Create a fish and train it on the random data
fish = Fish(512, 8, 6)
fish.train(src, tgt, labels)
print(fish.food) # Print the fish's food

# Create a fish school and optimize it on the random data
school = FishSchool(10, 512, 8, 6, 100)
school.forward(src, tgt, labels)
print(school.fish[0].food) # Print the first fish's food
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "swarms-torch"
version = "0.0.7"
version = "0.0.9"
description = "swarms-torch - Pytorch"
license = "MIT"
authors = ["Kye Gomez <[email protected]>"]
Expand All @@ -30,6 +30,8 @@ packages = [
[tool.poetry.dependencies]
python = "^3.6"
torch = "*"
einops = "*"



[tool.poetry.dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions swarms_torch/fish_school.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import torch
from torch import nn
from torch.nn import Transformer, CrossEntropyLoss
from torch.nn import CrossEntropyLoss, Transformer
from torch.optim import Adam


Expand Down

0 comments on commit 6f1923c

Please sign in to comment.