Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/everyai/classfier/classfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ def __init__(
)
self.model_config = None
self.model_path = (
MODEL_PATH
/ f"{self.model_name}_{self.tokenizer_name}_{self.data_name}.pkl"
MODEL_PATH / f"{self.model_name}_{self.tokenizer_name}_{self.data_name}.pkl"
)
self.pipeline = pipeline if pipeline is not None else None

Expand All @@ -186,9 +185,7 @@ def load_data(self, texts, labels, data_name):
raise ValueError("Length of texts and labels should be same")
self.texts = texts
self.labels = labels
logging.info(
f"Loading data: {data_name} to classfier {self.model_name}"
)
logging.info(f"Loading data: {data_name} to classfier {self.model_name}")
self.data_name = data_name
self.classfier_name = (
f"{self.model_name}_{self.tokenizer_name}_{self.data_name}"
Expand Down Expand Up @@ -288,9 +285,7 @@ def __init__(self, **classfiy_config):
else:
logging.warning("Split size not provided or not valid")
if self.texts is None or self.labels is None or self.data_name is None:
logging.warning(
"Data not provided, please use the load_data method"
)
logging.warning("Data not provided, please use the load_data method")
if "device" in classfiy_config and classfiy_config["device"] == "cuda":
logging.warning(
"Cuda is not supported in sklearn and setting device to cpu"
Expand Down Expand Up @@ -359,8 +354,7 @@ def _split_data(self, x, y):
x_train,
y_train,
train_indices,
test_size=self.valid_size
/ (self.train_size + self.valid_size),
test_size=self.valid_size / (self.train_size + self.valid_size),
random_state=42,
)
)
Expand Down
10 changes: 7 additions & 3 deletions src/everyai/classfier/multi_feature/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
class CrossAttentionFusion(nn.Module):
def __init__(self, d1, d2, d3, hidden_dim, output_dim, num_heads):
super(CrossAttentionFusion, self).__init__()
self.cross_attention = nn.MultiheadAttention(embed_dim=hidden_dim, num_heads=num_heads)
self.cross_attention = nn.MultiheadAttention(
embed_dim=hidden_dim, num_heads=num_heads
)
self.fc1 = nn.Linear(hidden_dim, output_dim)

def forward(self, f1, f2, f3):
# 将所有特征拼接后输入注意力模块
merged_features = torch.cat((f1, f2, f3), dim=-1).unsqueeze(0) # 添加batch维度
attn_output, _ = self.cross_attention(merged_features, merged_features, merged_features)
attn_output, _ = self.cross_attention(
merged_features, merged_features, merged_features
)
return torch.relu(self.fc1(attn_output.squeeze(0)))