Code Snippets Python

Short texts Python 🧑‍💻 Code snippets Python ✍️ Reading lists Python 👀

vd_experiment_multineat_2.py

#VDExperiment Class def create_substrate(dim): “”” The function to create two-sheets substrate configuration with specified dimensions of each sheet. Arguments: dim: The dimensions accross X, Y axis of the sheet “”” # Building sheet configurations of inputs and outputs inputs = create_sheet_space(-1, 1, dim, -1) outputs = create_sheet_space(-1, 1, dim, 0) substrate = NEAT.Substrate( inputs, [], […]

AtomicDEX-Desktop Supported Coins Report

#!/usr/bin/env python3 import sys import csv import requests VERSION = “0.5.2” BRANCH = “master” protocols = [] wallet_only = 0 if len(sys.argv) > 1: VERSION = sys.argv[1] if len(sys.argv) > 2: BRANCH = sys.argv[2] r = requests.get(f”https://raw.githubusercontent.com/KomodoPlatform/atomicDEX-Desktop/{BRANCH}/assets/config/{VERSION}-coins.json”) resp = r.json() ordered_coins = list(resp.keys()) ordered_coins.sort() output_filename = f”atomicdex_desktop_{VERSION}_{BRANCH}_coins_report.csv” with open(output_filename, ‘w’, newline=”) as file: writer = […]

T5ForSequenceClassification

import torch import copy from torch import nn from transformers import T5PreTrainedModel from transformers.models.t5.modeling_t5 import T5Stack from transformers.modeling_outputs import SequenceClassifierOutput from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss def mean_pooling(inputs, mask): token_embeddings = inputs input_mask_expanded = mask.unsqueeze(-1).expand(token_embeddings.size()).float() sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1) sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9) return sum_embeddings / sum_mask class MeanPooler(nn.Module): “”” Calcualte simple average […]

vd_experiment_multineat_3.py

#VDExperiment Class def create_sheet_space(start, stop, dim, z): “”” The function to create list with coordinates for a specific sheet of the substrate. Arguments: start: The start value by particular coordinate axis stop: The stop value by particular coordinate axis dim: The dimensions accross X, Y axis z: The Z coordinatre of this sheet in the […]