Text Classification
Transformers
Safetensors
yield-weather-soil
crop-yield
multi-temporal
regression
yield-estimation
custom_code
Instructions to use ICICLE-AI/yield-estimation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ICICLE-AI/yield-estimation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ICICLE-AI/yield-estimation", trust_remote_code=True)# Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("ICICLE-AI/yield-estimation", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Delete modeling_yield.py
Browse files- modeling_yield.py +0 -88
modeling_yield.py
DELETED
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
|
| 4 |
-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
| 5 |
-
sys.path.insert(0, str(PROJECT_ROOT))
|
| 6 |
-
|
| 7 |
-
import torch
|
| 8 |
-
from torch import nn
|
| 9 |
-
from transformers import PreTrainedModel
|
| 10 |
-
from transformers.modeling_outputs import ModelOutput
|
| 11 |
-
from dataclasses import dataclass
|
| 12 |
-
|
| 13 |
-
from .configuration_yield import YieldConfig
|
| 14 |
-
from .yield_transformer import YieldTransformer
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
@dataclass
|
| 18 |
-
class YieldModelOutput(ModelOutput):
|
| 19 |
-
loss: torch.Tensor | None = None
|
| 20 |
-
logits: torch.Tensor | None = None
|
| 21 |
-
predictions: torch.Tensor | None = None
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
class YieldForRegression(PreTrainedModel):
|
| 25 |
-
config_class = YieldConfig
|
| 26 |
-
base_model_prefix = "yield_model"
|
| 27 |
-
|
| 28 |
-
def __init__(self, config: YieldConfig):
|
| 29 |
-
super().__init__(config)
|
| 30 |
-
|
| 31 |
-
self.yield_model = YieldTransformer(
|
| 32 |
-
w_dim=config.W,
|
| 33 |
-
soil_dim=config.S,
|
| 34 |
-
d_model=config.d_model,
|
| 35 |
-
nhead=config.nhead,
|
| 36 |
-
num_layers=config.num_layers,
|
| 37 |
-
dim_ff=config.dim_ff,
|
| 38 |
-
dropout=config.dropout,
|
| 39 |
-
use_crop=config.use_crop,
|
| 40 |
-
crop_emb_dim=config.crop_emb_dim,
|
| 41 |
-
max_weeks=max(32, config.K),
|
| 42 |
-
pool=config.pool,
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
self.post_init()
|
| 46 |
-
|
| 47 |
-
def forward(
|
| 48 |
-
self,
|
| 49 |
-
weather,
|
| 50 |
-
soil,
|
| 51 |
-
crop_id,
|
| 52 |
-
labels=None,
|
| 53 |
-
horizon_idx=None,
|
| 54 |
-
causal=True,
|
| 55 |
-
return_sequence=False,
|
| 56 |
-
return_dict=True,
|
| 57 |
-
):
|
| 58 |
-
if horizon_idx is None:
|
| 59 |
-
horizon_idx = weather.shape[1]
|
| 60 |
-
|
| 61 |
-
logits = self.yield_model(
|
| 62 |
-
weather,
|
| 63 |
-
soil,
|
| 64 |
-
crop_id,
|
| 65 |
-
horizon_idx=horizon_idx,
|
| 66 |
-
causal=causal,
|
| 67 |
-
return_sequence=return_sequence,
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
y_mean = torch.tensor(self.config.y_mean, device=logits.device, dtype=logits.dtype)
|
| 71 |
-
y_std = torch.tensor(self.config.y_std, device=logits.device, dtype=logits.dtype)
|
| 72 |
-
|
| 73 |
-
#predictions = torch.expm1(logits * y_std + y_mean)
|
| 74 |
-
predictions = logits * y_std + y_mean
|
| 75 |
-
|
| 76 |
-
loss = None
|
| 77 |
-
if labels is not None:
|
| 78 |
-
labels_norm = (labels - y_mean) / y_std
|
| 79 |
-
loss = nn.functional.mse_loss(logits, labels_norm)
|
| 80 |
-
|
| 81 |
-
if not return_dict:
|
| 82 |
-
return (loss, logits, predictions)
|
| 83 |
-
|
| 84 |
-
return YieldModelOutput(
|
| 85 |
-
loss=loss,
|
| 86 |
-
logits=logits,
|
| 87 |
-
predictions=predictions,
|
| 88 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|