Skip to content

Instantly share code, notes, and snippets.

View sourabhparsekar's full-sized avatar
💭
something new is always happening......

sourabh_parsekar sourabhparsekar

💭
something new is always happening......
View GitHub Profile
@sourabhparsekar
sourabhparsekar / .py
Created October 7, 2024 08:52
Bert Score
from bert_score import BERTScorer
def calculate_bert_score(generated_answers, ground_truth):
scorer = BERTScorer(model_type='bert-base-uncased')
P, R, F1 = scorer.score(generated_answers, ground_truth)
for i, (p, r, f1) in enumerate(zip(P, R, F1)):
print(f"Pair {i + 1} - BERTScore Precision: {p.mean():.4f}, Recall: {r.mean():.4f}, F1: {f1.mean():.4f}")
avg_precision = sum(p.mean() for p in P) / len(P)
avg_recall = sum(r.mean() for r in R) / len(R)
avg_f1 = sum(f1.mean() for f1 in F1) / len(F1)
@sourabhparsekar
sourabhparsekar / .py
Created October 7, 2024 08:45
Rouge Score
from rouge_score import rouge_scorer
def calculate_rouge_scores(generated_answers, ground_truth):
scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=True)
total_rouge1, total_rouge2, total_rougeL = 0, 0, 0
for gen, ref in zip(generated_answers, ground_truth):
scores = scorer.score(gen, ref)
total_rouge1 += scores['rouge1'].fmeasure
total_rouge2 += scores['rouge2'].fmeasure
total_rougeL += scores['rougeL'].fmeasure
@sourabhparsekar
sourabhparsekar / .py
Last active October 7, 2024 08:37
Bleu Score
from nltk.translate.bleu_score import corpus_bleu
def calculate_bleu_score(machine_results, reference_texts):
bleu_score = corpus_bleu([[ref.split()] for ref in reference_texts], [gen.split() for gen in machine_results])
print(f'BLEU Score: {bleu_score}')
# BLEU Score for Finetuned:
# BLEU Score: 0.2119600445859861
# BLEU Score for Non-Finetuned:
# BLEU Score: 0.11573503531718608
You will act as a synthetic instruction data generator based on the given URL. Generate a minimum of 15 synthetic data which is intended to be a comprehensive or exhaustive treatment of the subject matter..
* Please act as a tutor and create a high quality detailed synthetic questions and answers from only using the context provided by the user.
* Ensure data teaches concepts step-by-step and focusses in improving reasoning skills.
* Focus on generating questions and answers about under-represented topics and knowledge gaps.
* Generate multiple combinations for detailed questions and answers such that the entire context is covered in the generated synthetic data
Generate a Microsoft Excel - CSV compatible response with below columns separated by, and text in double quotes
1. 'instruction':
* Ask a clear question related to the topics that requires logical thinking or common sense reasoning
@sourabhparsekar
sourabhparsekar / SmartContractFetchBalance.java
Created April 1, 2022 07:15
SmartContract Fetch Balance of an address
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.http.HttpService;
import org.web3j.token.Token;
import org.web3j.tx.gas.ContractGasProvider;
import org.web3j.tx.gas.StaticGasProvider;
class SmartContractFetchBalance {
@sourabhparsekar
sourabhparsekar / SmartContractDeployment.java
Created April 1, 2022 06:29
SmartContract Deployment in JAVA with Web3J
import com.ethereum.smartcontract.utils.Constants;
import com.ethereum.smartcontract.utils.Web3JUtils;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.http.HttpService;
import org.web3j.token.Token;
import org.web3j.tx.gas.ContractGasProvider;
import org.web3j.tx.gas.StaticGasProvider;
@sourabhparsekar
sourabhparsekar / build.gradle
Created April 1, 2022 05:39
Solidity, Node configurations
plugins {
//other plugins go here
id 'java'
id 'org.web3j' version '4.8.7' //Web3J Plugin to interact with Smart Contract
}
solidity {
executable = './src/main/resources/solc-windows.exe' // Path to Solc Compiler file
version = '0.8.0'
}
@sourabhparsekar
sourabhparsekar / setup.js
Created December 30, 2021 15:58
setup initial requests and wallet
//called only once after the page loads or is refreshed
useEffect(() => {
async function setup() {
const name = await loadContractName();
setName(name);
const symbol = await loadContractSymbol();
setSymbol(symbol);
@sourabhparsekar
sourabhparsekar / connect.js
Created December 30, 2021 15:55
web3.js interaction with Ethereum
// alchemy key from .env file
const alchemyKey = process.env.REACT_APP_ALCHEMY_KEY;
// load alchemy web3.js dependency
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
// configure web3js to use alchemy key
const web3 = createAlchemyWeb3(alchemyKey);
// load the contract abi [contract abi]
const contractABI = require("../contract-abi.json");
// deployed smart contract address from .env file
const contractAddress = process.env.REACT_APP_CONTRACT_ADDRESS;
@sourabhparsekar
sourabhparsekar / .env
Created December 30, 2021 15:30
Alchemy React UI
REACT_APP_ALCHEMY_KEY = https://eth-ropsten.ws.alchemyapi.io/v2/<key>
REACT_APP_CONTRACT_ADDRESS=<deployed contract address>