How to use in_each method in Sure

Best Python code snippet using sure_python

convert.py

Source: convert.py Github

copy

Full Screen

...32 else:33 setattr(tgt, key, src[key])34 else:35 if recursive:36 tgt = util.tool.in_each(src, lambda x : Common.to_args(x, recursive))37 else:38 tgt = src39 return tgt4041class List(object):42 def to_bert_msk_and_idx(src, source_len, max_len, bias):43 idx = util.tool.in_each(src, lambda x : [(1, 1)] + x[1 :])44 idx = util.tool.in_each(idx, lambda x : util.tool.idx_extender(x, max_len, 0, bias = bias))45 msk = util.tool.in_each(source_len, lambda x : [1] * x + [0] * (max_len - x))46 return idx, msk4748 def to_str(src):49 if isinstance(src, str):50 return src51 out = ""52 for ele in src:53 out += str(ele)54 return out5556 def to_bert_token_idx(src, tokener, max_len = 256):57 x = tokener.convert_tokens_to_ids(tokener.tokenize(util.convert.List.to_str(src)))58 # space maybe convert into anything59 if src == " ":60 x = [100]61 return x[:min(len(x),max_len)]6263 def to_bert_info(inputs, tokener, pad, cls, device, max_len = 256):64 raw_source = util.tool.in_each(inputs, lambda x : util.convert.List.to_bert_token_idx(x, tokener, max_len))65 source_len = util.tool.in_each(raw_source, lambda x : len(x) + 1)66 source, pad_idx = util.tool.pad([[[cls]] * len(inputs), raw_source], pad)67 if source == []:68 mmax_len = 069 else:70 mmax_len = len(source[0])71 source_idx, source_msk = util.convert.List.to_bert_msk_and_idx(pad_idx, source_len, mmax_len, -1)72 return (torch.Tensor(source).long().to(device), torch.Tensor(source_idx).long().to(device), torch.Tensor(source_msk).long().to(device)), source_len7374 def to_xlm_info(inputs, tokener, pad, cls, device, max_len = 256):75 raw_source = util.tool.in_each(inputs, lambda x : util.convert.List.to_bert_token_idx(x, tokener, max_len))76 source_len = util.tool.in_each(raw_source, lambda x : len(x) + 1)77 source, pad_idx = util.tool.pad([[[cls]] * len(inputs), raw_source], pad)78 if source == []:79 mmax_len = 080 else:81 mmax_len = len(source[0])82 source_idx, source_msk = util.convert.List.to_bert_msk_and_idx(pad_idx, source_len, mmax_len, -1)83 return torch.Tensor(source).long().to(device), torch.Tensor(source_msk).long().to(device)8485 def to_bert_info2(inputs1, inputs2, tokener, pad, cls, sep, device, max_len = 256):86 raw_source1 = util.tool.in_each(inputs1, lambda x : util.convert.List.to_bert_token_idx(x, tokener, max_len))87 raw_source2 = util.tool.in_each(inputs2, lambda x : util.convert.List.to_bert_token_idx(x, tokener, max_len))88 raw_source = util.tool.in_each(zip(raw_source1, raw_source2), lambda x : x[0] + [sep] + x[1] + [sep])89 source_len = util.tool.in_each(raw_source, lambda x : len(x) + 1)90 source, pad_idx = util.tool.pad([[[cls]] * len(raw_source), raw_source], pad)91 if source == []:92 max_len = 093 else:94 max_len = len(source[0])95 source_idx, source_msk = util.convert.List.to_bert_msk_and_idx(pad_idx, source_len, max_len, -1) ...

Full Screen

Full Screen

identify_confused.py

Source: identify_confused.py Github

copy

Full Screen

1import pandas as pd2from xlwt import Workbook3import os4current_run_folder = "resnet50_0.001/​"5resnet_files_list = os.listdir(current_run_folder)6df_dict = {}7for each in resnet_files_list:8 data_frame = pd.read_csv(current_run_folder + each)9 data_frame = data_frame.drop(index=80)10 data_frame = data_frame.drop("other", axis=1)11 classes = data_frame['Ground_Truth'].tolist()12 row_list = []13 class_confusion_rate = {}14 for out_each in classes:15 for in_each in range(len(classes)):16 if out_each != classes[in_each] and data_frame[out_each][in_each] > 0:17 dict_val = {18 'predicted_class': out_each,19 'actual_class': classes[in_each],20 'value': data_frame[out_each][in_each]21 }22 row_list.append(dict_val)23 if out_each not in class_confusion_rate:24 class_confusion_rate[out_each] = 025 if classes[in_each] not in class_confusion_rate:26 class_confusion_rate[classes[in_each]] = 027 class_confusion_rate[out_each] += data_frame[out_each][in_each]28 class_confusion_rate[classes[in_each]] += data_frame[out_each][in_each]29 print(out_each, classes[in_each], data_frame[out_each][in_each])30 output_dataframe = pd.DataFrame(row_list, columns=['actual_class', 'predicted_class', 'value'])31 output_dataframe = output_dataframe.sort_values(by=['value'], ascending=False)32 output_dataframe = output_dataframe.reset_index(drop=True)33 max_val, min_val = output_dataframe["value"].max(), output_dataframe["value"].min()34 output_dataframe["normalized"] = (output_dataframe["value"] - min_val) /​ (max_val - min_val)35 output_dataframe["normalized"] = output_dataframe["normalized"].round(decimals=2)36 # output_dataframe.to_csv("confused_pairs.csv", index=False)37 output_dataframe1 = pd.DataFrame.from_dict(class_confusion_rate, orient='index', columns=["confusions_involved"])38 output_dataframe1 = output_dataframe1.sort_values(by=['confusions_involved'], ascending=False)39 # output_dataframe1 = output_dataframe1.reset_index(drop=True)40 df_dict[each.replace("confusion_matrix-", "")] = output_dataframe41 df_dict[each.replace("confusion_matrix-", "") + "_confusion_rates"] = output_dataframe142 print(f'finished {each}')43with pd.ExcelWriter(current_run_folder.replace("/​", "") + '.xlsx', engine="openpyxl", mode='w') as writer:44 for key, value in df_dict.items():...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How Evolution Of HTTP/2 From HTTP/1 Changed The Web

Ever came across the situation where you really need to open a web page fast and it’s taking forever because of slow internet speed? May be someone in your network is downloading a torrent choking the bandwidth?

A Guide For Testing Fintech Applications(With Examples)

In today’s scenario, software testing has become an important entity across every domain for the benefits it offers. We have already explored a lot about software testing in general in our post need of software testing.

How to Test a Mobile Website Using LambdaTest

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Mobile Testing Tutorial.

Agile Vs Waterfall Methodology

Before development of a project begins, the project manager’s job is to determine which methodology should be used for the project life cycle. The 2 most popular methodologies are

Common Bugs in User Interface Design

In human physiology, vision plays a major role as 83% of the information humans perceive is via sight. So, your website should never lack in visual appeal. In web design, this is even more important. Every new iteration of design leaves some minor deviations. Sometimes, these minor visual deviations can be very hard to fix or unknowingly break the whole user experience. Hence, it is necessary to make sure that your website provides a perfect and working interface design to the user.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful