import torch from transformers import T5Tokenizer, T5ForConditionalGeneration from rdkit…
- User
import torch from transformers import T5Tokenizer, T5ForConditionalGeneration from rdkit import Chem, RDLogger from rdkit.Chem import AllChem, DataStructs import numpy as np
Disable RDKit logging
RDLogger.DisableLog('rdApp.*')
class SimpleChemT5: def init(self, model_path="GT4SD/multitask-text-and-chemistry-t5-base-augm"): self.tokenizer = T5Tokenizer.from_pretrained(model_path) self.model = T5ForConditionalGeneration.from_pretrained(model_path) self.device = "cuda" if torch.cuda.is_available() else "cpu" self.model.to(self.device)
codedef predict_product(self, reactant, max_length=128, num_beams=5): # Handle batch or single input if isinstance(reactant, str): reactant = [reactant] # Create input prompts with reaction type context input_texts = [f"predict product: {r}" for r in reactant] # Tokenize input inputs = self.tokenizer(input_texts, return_tensors="pt", padding=True, truncation=True, max_length=max_length) # Move inputs to device inputs = {k: v.to(self.device) for k, v in inputs.items()} # Generate prediction with torch.no_grad(): outputs = self.model.generate( input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"], max_length=max_length, num_beams=num_beams, early_stopping=True, temperature=0.1, # Add some randomness to generation do_sample=True ) # Decode predictions predicted_products = self.tokenizer.batch_decode(outputs, skip_special_tokens=True) return predicted_products[0] if len(reactant) == 1 else predicted_products def calculate_similarity(self, smiles1, smiles2): """Calculate molecular similarity using [Redacted Person] fingerprints""" mol1 = Chem.MolFromSmiles(smiles1) mol2 = Chem.MolFromSmiles(smiles2) if mol1 is None or mol2 is None: return 0.0 fp1 = AllChem.GetMorganFingerprintAsBitVect(mol1, 2, nBits=1024) fp2 = AllChem.GetMorganFingerprintAsBitVect(mol2, 2, nBits=1024) return DataStructs.TanimotoSimilarity(fp1, fp2) Assistant
- User
our task is simple, for a given reactant we have to predict the product, give me a more closer full implementation?
Assistant
- User
this is the state of the art for our task?
Assistant
- User
oh ok, so what is the state of the art for our task?
Assistant
Based on the repository's README.md and paper citations, this work (SLM4CRP) appears to be the current state-of-the-art (SOTA) for chemical reaction prediction tasks. The repository links to Papers with Code badges that show SOTA status:
code[] []
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.