Advertisement
Guest User

Generate results for llama3 benchmarks on azure

a guest
Jul 22nd, 2024
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | Source Code | 0 0
  1. import re
  2. import pandas as pd
  3. import os
  4. results_dir = r'C:\code\azureml-assets-sagoswami-llama3_1_assets\assets\evaluation_results'
  5. dirs = ['gpt-4o', 'meta-llama-3', 'meta-llama3']
  6. folders = os.listdir(results_dir)
  7. out_folders = []
  8. for folder in folders:
  9. for d in dirs:
  10. if d in folder:
  11. out_folders.append(folder)
  12. continue
  13.  
  14. def parse_evaluation_results():
  15.  
  16. sections = []
  17. for folder in out_folders:
  18. file = os.path.join(results_dir, folder, 'spec.yaml')
  19. with open(file, 'r') as file:
  20. text = file.read()
  21. sections.append(text)
  22. results = []
  23.  
  24. for section in sections:
  25. model_name_match = re.search(r"model_name:\s*(\S+)", section)
  26. dataset_name_match = re.search(r"dataset_name:\s*(\S+)", section)
  27. accuracy_match = re.search(r"accuracy:\s*([\d.]+)", section)
  28.  
  29. if model_name_match and dataset_name_match and accuracy_match:
  30. result = {
  31. "model_name": model_name_match.group(1),
  32. "dataset_name": dataset_name_match.group(1),
  33. "accuracy": float(accuracy_match.group(1))
  34. }
  35. results.append(result)
  36.  
  37. return results
  38.  
  39.  
  40. def convert_to_markdown_table(results):
  41. # Create a dictionary to hold the data
  42. data = {}
  43.  
  44. for result in results:
  45. model_name = result["model_name"]
  46. dataset_name = result["dataset_name"]
  47. accuracy = f"{result['accuracy']:.3f}"
  48.  
  49. if dataset_name not in data:
  50. data[dataset_name] = {}
  51. data[dataset_name][model_name] = accuracy
  52.  
  53. # Convert the dictionary to a DataFrame
  54. df = pd.DataFrame(data).T
  55.  
  56. # Convert the DataFrame to a Markdown table
  57. markdown_table = df.to_markdown()
  58.  
  59. return markdown_table
  60.  
  61.  
  62. # Example usage
  63. file_path = r"C:\code\results.txt"
  64. results = parse_evaluation_results(file_path)
  65. markdown_table = convert_to_markdown_table(results)
  66. print(markdown_table)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement