{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "c82eb8a8", "metadata": {}, "outputs": [], "source": [ "import json, requests, urllib" ] }, { "cell_type": "code", "execution_count": 2, "id": "45a53227", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 3, "id": "5ee17bd2", "metadata": {}, "outputs": [], "source": [ "response = requests.get(\"https://huggingface.co/api/models?filter=co2_eq_emissions\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "805a29d7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Out of 78 models, 78 of them reported carbon emissions\n" ] } ], "source": [ "modelcount=0\n", "carboncount=0\n", "\n", "carbon_df = pd.DataFrame(columns=['name','task','carbon'])\n", "\n", "for model in response.json():\n", " modelcount+=1\n", " if model['private'] == False:\n", " try:\n", " readme = urllib.request.urlopen(\"https://huggingface.co/\"+model['modelId']+\"/raw/main/README.md\")\n", " for line in readme:\n", " decoded_line = line.decode(\"utf-8\")\n", " if 'co2_eq_emissions' in decoded_line:\n", " carboncount+=1\n", " #print(model['modelId'], model['pipeline_tag'], decoded_line.split(\":\")[1])\n", " try:\n", " carbon_df.at[carboncount,'name'] = str(model['modelId'])\n", " carbon_df.at[carboncount,'task'] = str(model['pipeline_tag'])\n", " carbon_df.at[carboncount,'carbon'] = float(decoded_line.split(\":\")[1].replace('\\n',''))\n", " except:\n", " carbon_df.at[carboncount,'name'] = str(model['modelId'])\n", " carbon_df.at[carboncount,'task'] = ''\n", " carbon_df.at[carboncount,'carbon'] = float(decoded_line.split(\":\")[1].replace('\\n',''))\n", " except:\n", " continue\n", "print(\"Out of \"+str(modelcount)+\" models, \"+str(carboncount)+ \" of them reported carbon emissions\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "ce21fde5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | name | \n", "task | \n", "carbon | \n", "
---|---|---|---|
1 | \n", "Aimendo/autonlp-triage-35248482 | \n", "text-classification | \n", "7.989145 | \n", "
2 | \n", "Anorak/nirvana | \n", "text2text-generation | \n", "4.214013 | \n", "
3 | \n", "AryanLala/autonlp-Scientific_Title_Generator-3... | \n", "text2text-generation | \n", "137.605741 | \n", "
4 | \n", "Crasher222/kaggle-comp-test | \n", "text-classification | \n", "60.744727 | \n", "
5 | \n", "Emanuel/autonlp-pos-tag-bosque | \n", "token-classification | \n", "6.210727 | \n", "