From 4dc98ee9d2fbba2a67e8c1e2807aaa3e4fe4a31c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 09:07:43 +0000 Subject: [PATCH] style: format code with Autopep8, isort and Ruff Formatter This commit fixes the style issues introduced in 1ed1e17 according to the output from Autopep8, isort and Ruff Formatter. Details: None --- src/everyai/classfier/classfy.py | 14 ++++---------- src/everyai/classfier/multi_feature/model.py | 10 +++++++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/everyai/classfier/classfy.py b/src/everyai/classfier/classfy.py index 309007c..0a92151 100644 --- a/src/everyai/classfier/classfy.py +++ b/src/everyai/classfier/classfy.py @@ -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 @@ -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}" @@ -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" @@ -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, ) ) diff --git a/src/everyai/classfier/multi_feature/model.py b/src/everyai/classfier/multi_feature/model.py index 275eee5..2783d77 100644 --- a/src/everyai/classfier/multi_feature/model.py +++ b/src/everyai/classfier/multi_feature/model.py @@ -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)))