├── .gitignore ├── Dockerfile ├── README.md ├── data ├── test.tsv ├── train.tsv └── train_ext.tsv ├── docker-compose.yml ├── intent_classifier.py ├── notebooks └── Train.ipynb ├── requirements.txt ├── roberta.py ├── server.py └── xlm-roberta-large-custom-trained ├── config.json └── label_encoder.pkl /.gitignore: -------------------------------------------------------------------------------- 1 | /classifier.log 2 | /notebooks/.ipynb_checkpoints/ 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official Python runtime as a parent image 2 | FROM huggingface/transformers-pytorch-cpu:latest 3 | 4 | # Set the working directory inside the container 5 | WORKDIR /app 6 | 7 | # Copy the current directory contents into the container at /app 8 | COPY ./requirements.txt /app/. 9 | 10 | # Install any needed packages specified in requirements.txt 11 | RUN pip install -r requirements.txt 12 | 13 | #stop server from going into sleep 14 | CMD ["sleep", "infinity"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Intent Detection using XLM-Roberta 2 | 3 | ## Overview 4 | 5 | This repository contains code and resources for building an Intent Detection model using the XLM-Roberta architecture. Intent detection is a common task in Natural Language Processing (NLP), where the goal is to determine the intent or purpose behind a user's input. 6 | 7 | In this project, we leverage the power of the Hugging Face Transformers library to fine-tune an XLM-Roberta model for intent detection tasks. The model can be used for various applications, including chatbots, virtual assistants, and customer support systems. 8 | 9 | ## Features 10 | 11 | - Preprocessing scripts for data preparation. 12 | - Fine-tuning scripts for training the XLM-Roberta model on your dataset. 13 | - Inference code for predicting intents using the trained model. 14 | - Example notebooks and usage instructions. 15 | 16 | ## Getting Started 17 | 18 | ### Prerequisites 19 | 20 | Before getting started, ensure you have the following prerequisites: 21 | 22 | - Python 3.x 23 | - PyTorch 24 | - Hugging Face Transformers library 25 | - Other dependencies as specified in `requirements.txt` 26 | 27 | ### Installation 28 | 29 | 1. Clone this repository to your local machine: 30 | 31 | ```shell 32 | git clone https://github.com/MLArtist/intent-detection-using-XLM-Roberta.git 33 | cd intent-detection-using-XLM-Roberta 34 | ``` 35 | 36 | 2. Install the required dependencies: 37 | 38 | ```shell 39 | pip install -r requirements.txt 40 | ``` 41 | 42 | ### Usage 43 | 44 | #### Option 1: Bare Metal 45 | 46 | To perform inference on your local machine without using Docker, follow these steps: 47 | 48 | 1. Download the fine-tuned model weights from the [Google Drive](https://drive.google.com/file/d/10Rqx_j4Q0AyZUeUDXLVqLph0Tsuo110g). 49 | 50 | 2. Place the downloaded files in the 'xlm-roberta-large-custom-trained' folder. 51 | 52 | 3. Once you have completed these steps, run the inference server: 53 | 54 | ```shell 55 | python -m server --model xlm-roberta-large-custom-trained 56 | ``` 57 | 4. Test the inference server 58 | 59 | ```shell 60 | curl http://localhost:8080/ready 61 | curl -X POST -H "Content-Type: application/json" -d '{"text": "when is the next flight to new york"}' http://localhost:8080/intent 62 | ``` 63 | #### Option 2: Via Docker 64 | 65 | To perform inference using Docker, follow these steps: 66 | 67 | 1. Download the fine-tuned model weights from the [Google Drive](https://drive.google.com/file/d/10Rqx_j4Q0AyZUeUDXLVqLph0Tsuo110g). 68 | 69 | 2. Place the downloaded files in the 'xlm-roberta-large-custom-trained' folder. 70 | 71 | 3. Build the Docker image: 72 | 73 | ```shell 74 | docker build -t my-roberta-app -f Dockerfile . 75 | ``` 76 | 77 | 4. Run the Docker container, mapping port 8080 (or your preferred port) and specifying the model: 78 | 79 | ```shell 80 | docker-compose -f docker-compose.yml up 81 | ``` 82 | 5. test the inference server 83 | 84 | ```shell 85 | curl http://localhost:8080/ready 86 | curl -X POST -H "Content-Type: application/json" -d '{"text": "when is the next flight to new york"}' http://localhost:8080/intent 87 | ``` 88 | 89 | ### Training Instructions 90 | 91 | Use the example notebook `Train.ipynb` in the `notebooks/` directory for detailed training and offline model evaluation. 92 | 93 | ## Acknowledgments 94 | 95 | - [Hugging Face Transformers](https://github.com/huggingface/transformers) 96 | 97 | ## Authors 98 | 99 | - [Amit Kumar](https://github.com/MLArtist) 100 | 101 | For any inquiries or issues, please open an [issue](https://github.com/MLArtist/intent-detection-using-XLM-Roberta/issues). 102 | -------------------------------------------------------------------------------- /data/test.tsv: -------------------------------------------------------------------------------- 1 | i would like to find a flight from charlotte to las vegas that makes a stop in st. louis flight 2 | on april first i need a ticket from tacoma to san jose departing before 7 am airfare 3 | on april first i need a flight going from phoenix to san diego flight 4 | i would like a flight traveling one way from phoenix to san diego on april first flight 5 | i would like a flight from orlando to salt lake city for april first on delta airlines flight 6 | i need a flight from toronto to newark one way leaving wednesday evening or thursday morning flight 7 | monday morning i would like to fly from columbus to indianapolis flight 8 | on wednesday april sixth i would like to fly from long beach to columbus after 3 pm flight 9 | after 12 pm on wednesday april sixth i would like to fly from long beach to columbus flight 10 | are there any flights from long beach to columbus on wednesday april sixth flight 11 | find a flight from memphis to tacoma dinner flight 12 | on next wednesday flight from kansas city to chicago should arrive in chicago around 7 pm return flight on thursday flight 13 | show flight and prices kansas city to chicago on next wednesday arriving in chicago by 7 pm flight+airfare 14 | flight on american from miami to chicago arrive in chicago about 5 pm flight 15 | find flights arriving new york city next saturday flight 16 | find nonstop flights from salt lake city to new york on saturday april ninth flight 17 | show flights from burbank to milwaukee for today flight 18 | show flights tomorrow evening from milwaukee to st. louis flight 19 | show flights saturday evening from st. louis to burbank flight 20 | show flights from burbank to st. louis on monday flight 21 | show flights from burbank to milwaukee on monday flight 22 | show flights tuesday evening from milwaukee to st. louis flight 23 | show flights wednesday evening from st. louis to burbank flight 24 | which flights travel from kansas city to los angeles flight 25 | what flights travel from las vegas to los angeles flight 26 | which flights travel from kansas city to los angeles on april ninth flight 27 | which flights travel from las vegas to los angeles california and arrive on april ninth between 4 and 5 pm flight 28 | which flights on us air go from orlando to cleveland flight 29 | which flights travel from cleveland to indianapolis on april fifth flight 30 | which flights travel from indianapolis to san diego on april fifth flight 31 | which flights go from cleveland to indianapolis on april fifth flight 32 | which flights travel from nashville to tacoma flight 33 | does tacoma airport offer transportation from the airport to the downtown area ground_service 34 | which flights travel from tacoma to san jose flight 35 | what day of the week do flights from nashville to tacoma fly on day_name 36 | what are the flights from tacoma to san jose flight 37 | what days of the week do flights from san jose to nashville fly on day_name 38 | i need a flight that goes from boston to orlando flight 39 | are there any flights from boston to orlando connecting in new york flight 40 | are there any flights from boston to orlando connecting in columbus flight 41 | does this flight serve dinner flight 42 | i need a flight from charlotte to miami flight 43 | i need a nonstop flight from miami to toronto flight 44 | i need a nonstop flight from toronto to st. louis flight 45 | i need a flight from toronto to st. louis flight 46 | i need a flight from st. louis to charlotte flight 47 | i need a flight on united airlines from la guardia to san jose flight 48 | i need a flight from tampa to milwaukee flight 49 | i need a flight from milwaukee to seattle flight 50 | what meals are served on american flight 811 from tampa to milwaukee meal 51 | what meals are served on american flight 665 673 from milwaukee to seattle meal 52 | i need a flight from memphis to las vegas flight 53 | i need a flight from las vegas to ontario flight 54 | i need a flight from ontario to memphis flight 55 | which flights go from milwaukee to tampa and stop in nashville flight 56 | which flights leave newark after noon next saturday and arrive in los angeles flight 57 | which flights leave detroit and arrive at st. petersburg around 9 am flight 58 | which flights on northwest airline leave detroit and arrive at st. petersburg flight 59 | which flights leave chicago next tuesday and arrive in detroit around 6 pm flight 60 | show me round trip flights from chicago to detroit leaving next tuesday and returning the day after flight 61 | which round trip flights leave chicago next tuesday around 6 pm and arrive in detroit flight 62 | which round trip flights leave chicago next tuesday and arrive in detroit around 6 pm flight 63 | which flights leave on monday from montreal and arrive in chicago in the morning flight 64 | which flights leave chicago on april twelfth and arrive in indianapolis in the morning flight 65 | which flights leave on wednesday april thirteenth from indianapolis and arrive in montreal in the morning flight 66 | which flights leave april twelfth from indianapolis and arrive in montreal around 10 pm flight 67 | i 'd like to go from long beach to st. louis and i 'd like to stop in dallas i 'd also like to have lunch during my flight flight 68 | next wednesday i would like to leave kansas city on a trip to chicago which arrives in chicago around 7 pm flight 69 | i would like to return from chicago around 7 pm to kansas city flight 70 | i would like to leave this afternoon on an american flight from cincinnati to burbank flight 71 | on sunday evening i would like to leave montreal quebec on a flight to san diego california flight 72 | what are the flights on sunday from montreal quebec to san diego california flight 73 | on tuesday are the flights from san diego california to indianapolis indiana i would like the flight to be in the afternoon flight 74 | on thursday morning i would like a nonstop flight from indianapolis to toronto flight 75 | on friday morning i would like to fly from toronto to montreal flight 76 | i would like an early morning flight today from los angeles to charlotte flight 77 | on wednesday night i would like a flight from charlotte to newark flight 78 | on friday night i would like a flight from newark to los angeles flight 79 | find a flight from tampa to montreal by way of new york flight 80 | please find a flight from miami florida to las vegas nevada arriving before 4 o'clock pm flight 81 | please find a flight from las vegas to michigan flight 82 | please find a flight from detroit michigan to st. petersburg arriving before 10 pm flight 83 | please find a flight from st. petersburg to miami on thursday flight 84 | please find a flight from san diego to toronto on alaska airlines flight 85 | please find the flights from columbus to houston with a layover in nashville tomorrow flight 86 | please give me the flights from nashville to houston nonstop with dinner served flight 87 | please find flights available from kansas city to newark flight 88 | please find a flight that goes from kansas city to newark to orlando back to kansas city flight 89 | please find a flight from kansas city to newark flight 90 | please find a flight from newark to orlando flight 91 | please find a flight from orlando to kansas city flight 92 | i would like to fly from columbus to phoenix through cincinnati in the afternoon flight 93 | i would like to know what airports are in los angeles airport 94 | does the airport at burbank have a flight that comes in from kansas city flight 95 | which flights arrive in burbank from kansas city on saturdays in the afternoon flight 96 | which flights arrive in burbank from las vegas on saturday april twenty third in the afternoon flight 97 | which flights are available from orlando to cleveland that arrive around 10 pm flight 98 | what flights are available from indianapolis to san diego on april twenty first in the late afternoon flight 99 | what flights leave cleveland going to indianapolis on april twenty first in the morning flight 100 | which flights are available on april twenty first in the morning from nashville to tacoma flight 101 | which flights are available from tacoma to san jose in the morning on april twenty second flight 102 | which flights are available from san jose to nashville leaving in the morning on april twenty three flight 103 | what is the most expensive one way fare between detroit and westchester county airfare 104 | what airlines fly between detroit and westchester county airline 105 | what are the departure times from detroit to westchester county flight_time 106 | what is the latest flight from baltimore to oakland that serves dinner flight 107 | what is the earliest flight between baltimore and oakland that serves breakfast flight 108 | to what cities from boston does america west fly first class city 109 | what airline flies from boston to san diego airline 110 | what is the latest breakfast flight from dallas to tampa flight 111 | show me all lufthansa flights from seattle to boston with stopovers in minneapolis flight 112 | show me all flights from seattle to boston with stopovers in minneapolis flight 113 | list philadelphia to san francisco flights with stopovers in dallas flight 114 | show me the connecting flights between boston and denver and the types of aircraft used flight 115 | show me all the morning flights from philadelphia to fort worth flight 116 | show me all the flights from kansas city to st. paul flight 117 | show me northwest flight 608 from kansas city to st. paul flight 118 | show me all the flights from indianapolis to charlotte on monday flight 119 | what is the ground transportation between the charlotte airport charlotte airport and downtown charlotte ground_service 120 | show me all the flights from charlotte to minneapolis that leave at 2 pm or later on monday flight 121 | show me all the flights from charlotte to minneapolis on tuesday morning flight 122 | show me the direct flights from charlotte to minneapolis on tuesday morning flight 123 | show me flight us 1500 on monday from charlotte to minneapolis please flight 124 | show me all the flights from minneapolis to indianapolis on tuesday that leave after 2 pm flight 125 | show me the flights from minneapolis to indiana flight 126 | show me the flights in from minneapolis to indianapolis on tuesday afternoon flight 127 | show me flight us 1207 from indianapolis to charlotte on monday and flight us 1500 from charlotte to minneapolis on monday and flight twa 639 from minneapolis to indianapolis flight 128 | show me all the flights from las vegas to new york city flight 129 | which different airlines go from las vegas to new york city airline 130 | show me all the flights on america west and twa from las vegas to jfk on a friday flight 131 | what are the flights from tacoma to miami that leave after 6 pm tomorrow flight 132 | i 'd like to fly from san diego to houston on june tenth flight 133 | is there an american airlines flight from houston to newark on june tenth after 6 pm flight 134 | is there an american airlines flight from houston to newark on june tenth after 3 pm flight 135 | i need to get from cincinnati to denver on june sixth by 6 pm flight 136 | what 's the ground transportation in denver ground_service 137 | what 's the fare for a taxi to denver ground_fare 138 | what are the fares for ground transportation in denver ground_fare 139 | i need to fly from denver to westchester county on june seventh after 3 pm flight 140 | what 's the ground transportation in westchester county ground_service 141 | i need to take a united airlines flight on june eighth from westchester county to cincinnati after 3 pm flight 142 | what united airlines flights on june eighth go from westchester county to cincinnati flight 143 | on june eighth what flights go from westchester county to cincinnati flight 144 | does us air fly from cincinnati to denver on june sixth flight 145 | list the flights from cincinnati to denver on june sixth flight 146 | list the flights from denver to westchester county on june seventh flight 147 | list the flights from westchester county to cincinnati on june eighth flight 148 | list the flights from cincinnati to westchester county on june sixth flight 149 | list the flights from westchester county to denver on june seventh flight 150 | list the flights from denver to cincinnati on june eighth flight 151 | list the flights from denver to cincinnati on june sixth after 4 pm flight 152 | list the flights from cincinnati to westchester county on june seventh flight 153 | list the flights from westchester county to cincinnati on june seventh leaving after 5 pm flight 154 | what airlines off from love field between 6 and 10 am on june sixth airline 155 | what flights arrive at love field on june sixth flight 156 | list the flights from montreal to philly before 9 am flight 157 | list the flights from cleveland to memphis flight 158 | list the flights from memphis to cleveland flight 159 | list the flights from denver to baltimore arriving on july first flight 160 | list the flights from dallas to baltimore arriving july first flight 161 | list the flights from pittsburgh to baltimore arriving on july first flight 162 | list the flights on canadian airlines international flight 163 | how many canadian airlines international flights use j31 quantity 164 | how many canadian airlines international flights use aircraft 320 quantity 165 | how many canadian airlines flights use aircraft dh8 quantity 166 | show me the flights on american airlines which fly from st. petersburg to ontario canada with a stopover in st. louis flight 167 | show me the flights on american airlines which go from st. petersburg to ontario california by way of st. louis flight 168 | which airport is closest to ontario california airport 169 | show me the flights from houston to orlando flight 170 | show me the flights from orlando to houston flight 171 | show me the flights from detroit to las vegas flight 172 | show me the cheapest round trip coach fare from las vegas to detroit airfare 173 | show me the cheapest round trip coach fare on twa from las vegas to detroit airfare 174 | show me the delta flights which serve a snack to coach passengers flight 175 | what is meal code sb abbreviation 176 | what meals are available on dl 468 which al arrives in san francisco at 950 am meal 177 | show me the delta flights from tampa to san francisco flight 178 | show me delta flight 486 flight 179 | list the tower air flights on mondays flight 180 | list all tower air flights with meals flight 181 | what flights depart from baltimore flight 182 | what flights depart from baltimore and arrive at san francisco on a friday flight 183 | what flights leave from cincinnati in the morning and arrive in tampa flight 184 | which flights depart from tampa and arrive in cincinnati in the evening flight 185 | which flights depart from tampa in the early evening and arrive in cincinnati flight 186 | which flights depart from philadelphia and arrive in atlanta flight 187 | which flights depart from a atlanta and arrive in toronto flight 188 | which flights depart from toronto and arrive in washington dc flight 189 | which flights depart from new york and arrive in los angeles after 10 am flight 190 | how far is new york 's la guardia from downtown distance 191 | how far is toronto international from downtown distance 192 | how far is los angeles international from downtown distance 193 | how far is san francisco international from downtown distance 194 | how much is the limousine service in boston ground_fare 195 | how much is a limousine service in la guardia ground_fare 196 | how much is a limousine service in toronto international ground_fare 197 | how much is limousine service in los angeles ground_fare 198 | what airlines fly between washington dc and columbus ohio airline 199 | what flights are there between washington dc and columbus ohio flight 200 | what are the flights between washington dc and columbus ohio flight 201 | what are the fares for all flights between washington and columbus airfare 202 | at the charlotte airport how many different types of aircraft are there for us air aircraft 203 | list all us air flights arriving in charlotte on saturday at 1 pm flight 204 | what is the first class round trip airfare from india indianapolis to memphis airfare 205 | list all flights from memphis to miami flight 206 | list all flights and their fares from indianapolis to memphis on a monday morning flight+airfare 207 | list all flights and their fares from memphis to miami on a wednesday evening flight+airfare 208 | list all flights and their fares for all flights between miami and indianapolis flight+airfare 209 | list all flights from cleveland to kansas city on monday flight 210 | list all flights from kansas city to cleveland flight 211 | list all flights from cleveland to nashville flight 212 | list all flights from nashville to cleveland on sunday flight 213 | list all sunday flights from cleveland to nashville and their fares flight+airfare 214 | what airlines are departing from baltimore airline 215 | which airlines fly from baltimore to san francisco airline 216 | how long does a flight from baltimore to san francisco take distance 217 | which flights are leaving from kansas city to atlanta early monday morning flight 218 | which flights are leaving atlanta and arriving in st. louis close to 230 pm on tuesday flight 219 | please list flights from st. louis to st. paul which depart after 10 am thursday morning flight 220 | list flights from st. paul to kansas city friday in the evening with a meal included flight 221 | list early morning flights from cincinnati to tampa flight 222 | list early evening flights from tampa to cincinnati flight 223 | list evening flights from tampa to cincinnati flight 224 | list flights from philadelphia to atlanta friday am flight 225 | list flights from atlanta to toronto friday afternoon flight 226 | list flights from toronto to washington dc saturday am flight 227 | list flights from washington dc to philadelphia saturday pm flight 228 | list direct flights from new york city to los angeles after 10 am flight 229 | list the airfare for american airlines flight 19 from jfk to lax airfare+flight 230 | what is fare code m abbreviation 231 | list the distance in miles from boston airport to downtown boston distance 232 | list the distance in miles from new york 's la guardia airport to downtown new york city distance 233 | list the distance in miles from toronto international airport to downtown toronto distance 234 | list the distance in miles from san francisco international airport to san francisco downtown distance 235 | list limousine rates for the city of boston ground_fare 236 | list american airlines flights from houston to milwaukee departing friday pm flight 237 | list flights from houston to milwaukee friday pm flight 238 | list american airlines flights from milwaukee to san jose wednesday flight 239 | list american airlines flights from san jose to dallas friday afternoon flight 240 | list flights from dallas to houston arriving sunday afternoon flight 241 | list airlines flying from seattle to salt lake city airline 242 | what is the seating capacity for aircraft l10 capacity 243 | what is the seating capacity for delta be1 capacity 244 | list flights from seattle to salt lake city on delta l10 flight 245 | list flights from seattle to salt lake city on delta be1 flight 246 | list flights from boston to pittsburgh daily flight 247 | list flights from pittsburgh to newark daily flight 248 | list flights from newark to boston daily flight 249 | list us air flights leaving saturday from charlotte airport at 1 pm flight 250 | list us air flights leaving saturday from charlotte airport around 1 pm flight 251 | list first class airfare round trip from indianapolis to memphis airfare 252 | what is fare code f abbreviation 253 | list flights from memphis to miami wednesday evening flight 254 | list flights from miami to indianapolis sunday flight 255 | list flights from ontario california to orlando florida flight 256 | list flights from ontario california to salt lake city utah flight 257 | list flights from ontario california to salt lake city utah monday flight 258 | list flights from salt lake city utah to phoenix arizona monday flight 259 | list flights from salt lake city to phoenix arizona tuesday flight 260 | list flights from phoenix arizona to ontario california wednesday flight 261 | what airlines fly from baltimore to san francisco airline 262 | what is the fare for a first class round trip ticket from detroit to st. petersburg airfare 263 | what is the airfare for a round trip first class ticket from detroit to st. petersburg airfare 264 | kansas city to atlanta monday morning flights flight 265 | monday morning flights from atlanta to kansas city flight 266 | atlanta to st. louis tuesday before 230 pm flights flight 267 | st. louis to st. paul thursday after 10 am flight 268 | st. paul to kansas city friday night flight 269 | cleveland to kansas city arrive monday before 3 pm flight 270 | kansas city to cleveland flight arrive wednesday before 5 pm flight 271 | cleveland to nashville flight friday morning flight 272 | nashville to cleveland sunday before 9 flight 273 | first class flights pittsburgh to newark monday morning flight 274 | flights newark to los angeles wednesday morning flight 275 | los angeles to minneapolis thursday afternoon flight 276 | minneapolis to pittsburgh flight flight 277 | minneapolis to pittsburgh first class flight flight 278 | i would like flights leaving from milwaukee to orlando flight 279 | what does hp stand for abbreviation 280 | i would like flights from ontario to tacoma flight 281 | i would like flights from minneapolis to san diego flight 282 | i would like flights from salt lake city to cincinnati flight 283 | i would like to see flights from cincinnati to salt lake city flight 284 | i 'd like flights from new york to miami flight 285 | i would like flights from miami to new york flight 286 | i would like a flight leaving san francisco for san diego flight 287 | i would like flights from san diego to las vegas flight 288 | i would like a flight from san diego to las vegas flight 289 | i would like flights from las vegas to san francisco flight 290 | what does fare code bn mean abbreviation 291 | i would like to have the airline that flies toronto detroit and st. louis airline 292 | i would like a flight from toronto to detroit flight 293 | i would like a flight from detroit to st. louis flight 294 | i would like a flight from toronto to st. louis flight 295 | i would like flights from san francisco to long beach flight 296 | i would like flights leaving san francisco to san diego flight 297 | i would like a flight from san francisco to st. petersburg flight 298 | show me a one way flight from milwaukee to orlando leaving wednesday afternoon after 6 pm flight 299 | show me one way flights from milwaukee to orlando on wednesday flight 300 | show me flights from columbus to chicago first class that leave before 10 am flight 301 | show me the cheapest round trip between st. petersburg and detroit that arrives before 7 pm flight 302 | show me nonstop flights from kansas city to phoenix flight 303 | what is airline wn airline 304 | show me the cheapest first class round trip from new york to miami flight 305 | now show me all the round trips from new york to miami flight 306 | show me the cheapest one way flight from san francisco to houston flight 307 | now show me the cheapest one way flight from houston to boston flight 308 | show me the cheapest round trip fares from houston to boston airfare 309 | show me the cheapest round trip fares from san francisco to houston airfare 310 | show me the cheapest round trip fare from san francisco to houston on february twenty eighth 1994 airfare 311 | show me the cheapest one way fare from san francisco to houston on february twenty eighth 1994 airfare 312 | now show me ground transportation in houston on monday afternoon ground_service 313 | now show me one way flights from houston to boston flight 314 | and now show me ground transportation that i could get in boston late night ground_service 315 | show me airlines that have flights between toronto and detroit between detroit and st. louis and between st. louis and toronto airline 316 | show me round trip fares from toronto to detroit on delta northwest us air and united airlines airfare 317 | show me flights between detroit and st. louis on delta northwest us air and united airlines flight 318 | show me flights from montreal to orlando and long beach flight 319 | show me flights from montreal to orlando flight 320 | i need a flight on friday afternoon in june from new york to cleveland flight 321 | i need a flight from new york to los angeles on saturday evening on us air flight 322 | i 'd like a red eye flight from new york to los angeles on saturday evening on us air flight 323 | i 'd like a flight from new york to los angeles on saturday morning on us air flight 324 | i need a flight from san francisco to milwaukee on monday morning flight 325 | what does ua mean abbreviation 326 | i need a flight from milwaukee to washington dc on monday night flight 327 | how about flights from milwaukee to washington dc on tuesday mornings flight 328 | what meals are there on flight 382 from milwaukee to washington dc on tuesday morning meal 329 | i 'll need to rent a car in washington dc ground_service 330 | can i get a flight on tuesday night from washington dc to oakland flight 331 | how about from dc to oakland on wednesday morning flight 332 | how much does it cost to fly on twa from columbus to milwaukee airfare 333 | what does q mean abbreviation 334 | how much does it cost to fly from columbus to st. louis round trip on twa airfare 335 | what 's the cheapest flight from columbus to st. louis round trip on twa flight 336 | what 's the cheapest round trip flight on twa from columbus to st. paul flight 337 | i want to fly from milwaukee to los angeles flight 338 | can i get the shortest flight from milwaukee to orlando flight 339 | what is the shortest flight from milwaukee to long beach flight 340 | what does m mean abbreviation 341 | what does ap 57 mean abbreviation 342 | what is the shortest flight from milwaukee to st. petersburg flight 343 | what is the shortest flight from milwaukee to san diego flight 344 | what does ap 20 mean abbreviation 345 | can i get a flight today from san francisco to detroit michigan flight 346 | what 's the cheapest flight from san francisco to detroit today flight 347 | i want to fly from san francisco to milwaukee and from milwaukee to denver flight 348 | what 's the cheapest flight from san francisco to milwaukee flight 349 | i need to rent a car in milwaukee ground_service 350 | what 's the cheapest flight tomorrow from milwaukee to denver flight 351 | what ground transportation is available at denver ground_service 352 | what 's the cheapest flight from san francisco to denver flight 353 | what flights leave from cleveland and go to dallas flight 354 | show me all nonstop flights from st. petersburg to charlotte flight 355 | what airline is us airline 356 | show me flights between toronto and san diego flight 357 | what is phl abbreviation 358 | what is mci abbreviation 359 | show me the flights between oakland and salt lake city flight 360 | what does not sa mean abbreviation 361 | what is the earliest daily flight between oakland and salt lake city flight 362 | what airline is dl airline 363 | what is the latest daily flight between oakland and salt lake city flight 364 | show me the flights between los angeles and dallas flight 365 | what ground transportation is available from dallas fort worth airport to downtown dallas ground_service 366 | how many passengers can an l1011 aircraft hold capacity 367 | what is the seating capacity of a dc9 capacity 368 | what are the flights between dallas and phoenix flight 369 | what ground transportation is available between phoenix airport and downtown phoenix ground_service 370 | what is the seating capacity for the aircraft m80 capacity 371 | are there any flights between dallas and phoenix using a dc10 aircraft flight 372 | what airline is aa airline 373 | show me the flights between milwaukee and indiana flight 374 | what are the flights between milwaukee and pittsburgh flight 375 | what ground transportation is available between pittsburgh airport and downtown pittsburgh ground_service 376 | show me the flights between pittsburgh and washington dc flight 377 | what ground transportation is available between dca and downtown washington ground_service 378 | what are the flights between dca and milwaukee flight 379 | what ground transportation is available between milwaukee airport and downtown milwaukee ground_service 380 | determine the type of aircraft used on a flight from cleveland to dallas that leaves before noon aircraft 381 | find a flight between st. petersburg and charlotte the flight should leave in the afternoon and arrive as soon after 5 pm as possible it should be a nonstop flight flight 382 | list a flight on delta airlines from toronto to san diego flight 383 | list a flight on american airlines from toronto to san diego flight 384 | list a flight from toronto to san diego flight 385 | list flights from oakland to salt lake city leaving after 1700 wednesday flight 386 | list flights from oakland to salt lake city leaving after midnight thursday flight 387 | list flights between phoenix and las vegas flight 388 | list flights from las vegas to denver flight 389 | list flights from milwaukee to washington dc before 1200 flight 390 | list flights from washington dc to pittsburgh leaving after 1800 flight 391 | list flights from washington dc to pittsburgh flight 392 | list flights between pittsburgh and milwaukee flight 393 | i 'd like a flight to san diego from washington dc flight 394 | i 'd like to fly from cleveland to dallas flight 395 | i want to fly from washington dc to phoenix arizona flight 396 | i need a flight from phoenix to atlanta flight 397 | i would like to fly from atlanta to san diego flight 398 | i would like to fly from san diego to seattle flight 399 | i would like to fly from orlando to kansas city flight 400 | i need a flight from kansas city to minneapolis flight 401 | i need a flight from san diego to washington dc flight 402 | i need a flight from washington dc to san diego flight 403 | i need a round trip flight from san diego to washington dc and the fares flight+airfare 404 | i need a round trip from atlanta to washington dc and the fares leaving in the morning flight+airfare 405 | i need a round trip from phoenix to washington dc and the fare leaving in the morning flight+airfare 406 | what is the lowest fare for a flight from washington dc to boston airfare 407 | what is the lowest fare from washington dc to montreal airfare 408 | what is the lowest fare from toronto to washington dc airfare 409 | i want a flight from montreal to washington dc flight 410 | i want a flight from nashville to seattle that arrives no later than 3 pm flight 411 | i want a flight from memphis to seattle that arrives no later than 3 pm flight 412 | i need a flight from indianapolis to seattle arriving in seattle at 1205 pm flight 413 | i want a flight round trip from memphis to seattle flight 414 | i want to fly from nashville to seattle and i want the cheapest fare round trip flight 415 | i want to fly from memphis to seattle round trip with the cheapest fare flight 416 | i want to fly from indianapolis to seattle round trip with the cheapest fare flight 417 | please list flights from orlando to philadelphia flight 418 | please list flights from san francisco to charlotte flight 419 | please list flights from milwaukee to philadelphia flight 420 | please list flights from philadelphia to san francisco flight 421 | please show ground transportation to milwaukee ground_service 422 | please list flights from san francisco to milwaukee flight 423 | list flights from houston to denver flight 424 | list flights from houston to phoenix flight 425 | list flights from phoenix to houston flight 426 | list flights from newark to houston flight 427 | show flights from denver to houston flight 428 | show flights from st. petersburg to charlotte flight 429 | show flights from orlando to kansas city flight 430 | show flights from kansas city to minneapolis flight 431 | show flights from kansas city to orlando flight 432 | show flights from minneapolis to kansas city flight 433 | list flights from washington dc to boston flight 434 | list fares from washington dc to montreal airfare 435 | list flights from washington dc to montreal flight 436 | list fares from washington dc to toronto that should be good airfare 437 | list fares from washington dc to boston airfare 438 | list flights from washington dc to toronto flight 439 | list flights from toronto to washington dc flight 440 | list flights from oakland to salt lake city flight 441 | what flights go from dallas to phoenix flight 442 | what flights go from phoenix to salt lake city flight 443 | i need an early flight from milwaukee to denver flight 444 | what types of ground transportation are available in denver ground_service 445 | what flights go from denver to st. louis on tuesday morning flight 446 | is ground transportation available in st. louis ground_service 447 | i need to fly from st. louis to milwaukee on wednesday afternoon flight 448 | flights from washington to seattle flight 449 | flights from atlanta to seattle flight 450 | flights from san diego to seattle flight 451 | i would like flight information from phoenix to denver flight 452 | could i have flight information on flights from salt lake city to phoenix please flight 453 | could i have flight information on flights from pittsburgh to phoenix please flight 454 | i would like information on flights leaving from washington dc to denver flight 455 | i need information on flights from washington to boston that leave on a saturday flight 456 | i need the flights from washington to montreal on a saturday flight 457 | i need the fares on flights from washington to toronto on a saturday airfare 458 | i want to go from boston to washington on a saturday flight 459 | i need a flight from cleveland to dallas that leaves before noon see if too much information flight 460 | get fares from washington to boston airfare 461 | get saturday fares from washington to boston airfare 462 | get fares from washington to montreal airfare 463 | get saturday fares from washington to montreal airfare 464 | get saturday fares from washington to toronto airfare 465 | get the saturday fare from washington to toronto airfare 466 | list saturday flights from washington to boston flight 467 | list saturday flights from boston to washington flight 468 | get flights from milwaukee to dtw flight 469 | list flights from milwaukee to detroit flight 470 | get flights from detroit to toronto flight 471 | get flights from toronto to milwaukee flight 472 | get last flight from oakland to salt lake city on wednesday or first flight from oakland to salt lake city on thursday flight 473 | get first flight from oakland to salt lake city on thursday flight 474 | get last flight from oakland to salt lake city on wednesday flight 475 | list last wednesday flight from oakland to salt lake city flight 476 | get flight from toronto to san diego stopping at dtw flight 477 | get flights between st. petersburg and charlotte flight 478 | i need a flight from milwaukee to indianapolis leaving monday before 9 am flight 479 | i need a flight departing from milwaukee to indianapolis leaving monday before 8 am flight 480 | is there ground transportation available at the indianapolis airport ground_service 481 | i need flight information for a flight departing from indianapolis to cleveland departing tuesday at noon flight 482 | i need flight information for a flight departing from cleveland to milwaukee wednesday after 6 pm flight 483 | i need flight information for flights departing from cleveland going back to milwaukee wednesday after 5 pm flight 484 | i need flight information for flights departing from cleveland to milwaukee on wednesday after 5 pm flight 485 | i need a flight from denver to salt lake city on monday flight 486 | is there ground transportation available at the denver airport ground_service 487 | i need flight and airline information for a flight from denver to salt lake city on monday departing after 5 pm flight+airline 488 | is there ground transportation available at the salt lake city airport ground_service 489 | i need a flight from salt lake city to phoenix departing wednesday after 5 pm flight 490 | is there ground transportation available at the phoenix airport ground_service 491 | i need a flight from oakland to salt lake city on wednesday departing after 6 pm flight 492 | i need flight and fare information for thursday departing prior to 9 am from oakland going to salt lake city flight+airfare 493 | i need flight and fare information departing from oakland to salt lake city on thursday before 8 am flight+airfare 494 | i need flight numbers and airlines for flights departing from oakland to salt lake city on thursday departing before 8 am flight_no+airline 495 | i need flight numbers for those flights departing on thursday before 8 am from oakland going to salt lake city flight_no 496 | list airports in arizona nevada and california please airport 497 | list california nevada arizona airports airport 498 | list the arizona airport airport 499 | list california airports airport 500 | list flights from las vegas to phoenix flight 501 | list airports airport 502 | list wednesday night flights from oakland to salt lake city flight 503 | list flights from oakland to salt lake city before 6 am thursday morning flight 504 | which airlines fly between toronto and san diego airline 505 | please list afternoon flights between st. petersburg and charlotte flight 506 | what is tpa abbreviation 507 | what are the flights from cleveland to dallas flight 508 | please list only the flights from cleveland to dallas that leave before noon flight 509 | what type of aircraft are flying from cleveland to dallas before noon aircraft 510 | i need information on flights from indianapolis to seattle flight 511 | i need a flight from memphis to seattle flight 512 | i need a ticket from nashville to seattle airfare 513 | i need a ticket from nashville tennessee to seattle airfare 514 | i need flight information from milwaukee to tampa flight 515 | i need to rent a car at tampa ground_service 516 | i need a daily flight from st. louis to milwaukee flight 517 | i need flights departing from oakland and arriving salt lake city flight 518 | i need information on flights from toronto to san diego flight 519 | i want a flight from toronto to san diego flight 520 | i need information on flights between st. petersburg and charlotte flight 521 | i need the flight numbers of flights leaving from cleveland and arriving at dallas flight_no 522 | which flights go from new york to miami and back flight 523 | what does fare code qo mean abbreviation 524 | show me flights from milwaukee to orlando one way flight 525 | what the abbreviation us stand for abbreviation 526 | i 'd like a one way ticket from milwaukee to orlando either wednesday evening or thursday morning airfare 527 | show me flights from milwaukee to orlando flight 528 | what does fare code f mean abbreviation 529 | what does fare code h mean abbreviation 530 | what does fare code y mean abbreviation 531 | what are restrictions ap 57 abbreviation 532 | please show me first class flights from indianapolis to memphis one way leaving before 10 am flight 533 | now show me all round trip flights from burbank to seattle that arrive before 7 pm in seattle flight 534 | round trip flights from orlando to montreal please flight 535 | show me all delta airlines flights from montreal to orlando flight 536 | show me all flights from orlando to montreal please flight 537 | which airline is kw airline 538 | please list all flights from new york to miami any any type of class flight 539 | what does fare code bh mean abbreviation 540 | show me a return flight from miami to jfk please flight 541 | show me one way flights from milwaukee to orlando after 6 pm on wednesday flight 542 | show me the flights from indianapolis to memphis flight 543 | show me round trip flights from burbank to seattle flight 544 | show me round trip flights from orlando to montreal flight 545 | show me nonstop flights from montreal to orlando flight 546 | show me round trips between montreal and orlando flight 547 | show me round trip flights from montreal to orlando flight 548 | show me the cheapest one way flights from montreal to orlando flight 549 | show me the cheapest one way flights from orlando to montreal flight 550 | show me the cheapest economy flights from miami to new york flight 551 | kansas city to las vegas economy flight 552 | what airline is hp airline 553 | ground transportation in las vegas ground_service 554 | ground transportation for las vegas ground_service 555 | las vegas to baltimore economy flight 556 | baltimore to kansas city economy flight 557 | which airline is us airline 558 | columbus to chicago one way before 10 am flight 559 | st. petersburg to detroit flight 560 | from milwaukee to orlando one way after 5 pm wednesday flight 561 | and from milwaukee to atlanta before 10 am daily flight 562 | what airline is yx airline 563 | show me all flights from san jose to phoenix flight 564 | show me ground transportation in phoenix ground_service 565 | show me flights from phoenix to fort worth flight 566 | show me ground transportation in fort worth ground_service 567 | show me flights from fort worth to san jose flight 568 | show me first class flights from new york to miami round trip flight 569 | show me all round trip flights from new york to miami nonstop flight 570 | show me all round trip flights from miami to new york nonstop flight 571 | show me one way flights from indianapolis to memphis before 10 am on any day flight 572 | show me round trip flights from burbank to tacoma flight 573 | what does the restriction ap58 mean abbreviation 574 | what airline is as airline 575 | what airline is as as in sam airline 576 | show me nonstop flights from st. petersburg to toronto flight 577 | show me nonstop flights from toronto to st. petersburg flight 578 | show me the nonstop flights and fares from toronto to st. petersburg flight+airfare 579 | show me the nonstop flights from toronto to st. petersburg flight 580 | show me weekday flights from milwaukee to orlando one way flight 581 | list flights from chicago to san diego flight 582 | list flights from kansas city to denver flight 583 | list flights from denver to phoenix flight 584 | list flights from phoenix to las vegas flight 585 | list flights from las vegas to san diego flight 586 | list flights from chicago to kansas city in the morning flight 587 | list flights from houston to san jose flight 588 | list flights from houston to milwaukee flight 589 | list flights from milwaukee to san jose on wednesday flight 590 | list flights from san jose to dallas on friday flight 591 | list flights from dallas to houston flight 592 | list distance from airports to downtown in new york distance 593 | list airports in new york airport 594 | list airports in la airport 595 | list the airports in la airport 596 | list la city 597 | list flights from new york to la flight 598 | list flights from la guardia to burbank flight 599 | list flights from la to orlando flight 600 | list flights from ontario california to orlando flight 601 | list flights from indianapolis to memphis with fares on monday flight 602 | list flights from indianapolis to memphis on monday flight 603 | list flights from memphis to miami on wednesday flight 604 | list flights from miami to indianapolis on sunday flight 605 | list flights from charlotte on saturday afternoon flight 606 | list type of aircraft for all flights from charlotte aircraft 607 | list flights and fares from tacoma to orlando round trip leaving saturday returning next saturday flight+airfare 608 | what class is fare code q abbreviation 609 | list flights from orlando to tacoma on saturday of fare basis code of q flight 610 | list airfares for first class round trip from detroit to st. petersburg airfare 611 | list coach round trip airfare from detroit to st. petersburg airfare 612 | list flights from pittsburgh to newark on monday morning flight 613 | list flights from minneapolis to pittsburgh on friday flight 614 | list flights before 9 am from cincinnati to tampa flight 615 | list flights from cincinnati to tampa before noon flight 616 | list flights from tampa to cincinnati after 3 pm flight 617 | list airlines that fly from seattle to salt lake city airline 618 | list delta flights from seattle to salt lake city flight 619 | list seating capacities of delta flights from seattle to salt lake city capacity 620 | list delta flights from seattle to salt lake city with aircraft type flight 621 | what ground transportation is there in baltimore ground_service 622 | list ground transportation in baltimore ground_service 623 | list flights from baltimore to san francisco on friday flight 624 | give me the flights from los angeles to pittsburgh on tuesday flight 625 | give me the flights from pittsburgh to los angeles thursday evening flight 626 | give me the round trip flights from cleveland to miami next wednesday flight 627 | give me the fares for round trip flights from cleveland to miami next wednesday airfare 628 | give me the flights and fares for a trip to cleveland from miami on wednesday flight 629 | give me the fares from miami to cleveland next sunday airfare 630 | give me the flights from milwaukee to phoenix on saturday or sunday on american airlines flight 631 | give me the flights from phoenix to milwaukee on wednesday evening flight 632 | give me the flights from phoenix to milwaukee on wednesday on american airlines flight 633 | give me the flights from phoenix to milwaukee on american airlines flight 634 | give me the flights from phoenix to milwaukee flight 635 | give me the meal flights departing early saturday morning from chicago to seattle nonstop flight 636 | give me the flights from chicago to seattle saturday morning that have meals flight 637 | give me flights from seattle to chicago that have meals on continental flight 638 | give me the flights from seattle to chicago that have meals on continental saturday morning flight 639 | give me the flights from chicago to seattle on continental that have meals early saturday morning flight 640 | give me a combination of continental flights from chicago to seattle that have meals early saturday morning flight 641 | give me the saturday morning flights with meals from chicago to minneapolis flight 642 | give me the saturday morning flights on continental that have meals from chicago to minneapolis flight 643 | give me the saturday morning flights from chicago to st. paul on continental that have meals flight 644 | give me the flights from new york to las vegas nonstop flight 645 | give me the flights from memphis to las vegas nonstop flight 646 | give me the cheapest round trip flights from indianapolis to orlando around december twenty fifth flight 647 | i need a friday flight from newark to tampa flight 648 | i need a sunday flight from tampa to charlotte flight 649 | give me a flight from charlotte to baltimore on tuesday morning flight 650 | can i have a morning flight from baltimore to newark please flight 651 | cheapest round trip fare from or indianapolis to orlando on december twenty fifth airfare 652 | cheapest one way fare from indianapolis to orlando on december twenty seventh airfare 653 | flight number from dallas to houston flight_no 654 | flight number from houston to dallas flight_no 655 | saturday flight on american airlines from milwaukee to phoenix flight 656 | flight numbers on american airlines from phoenix to milwaukee flight_no 657 | flight numbers from chicago to seattle flight_no 658 | flight numbers from chicago to seattle on continental flight_no 659 | flight numbers from seattle to chicago on continental flight_no 660 | is there a fare from pittsburgh to cleveland under 200 dollars airfare 661 | how much is coach flight from pittsburgh to atlanta airfare 662 | newark to tampa on friday flight 663 | tampa to charlotte sunday morning flight 664 | charlotte to baltimore on tuesday flight 665 | baltimore to newark wednesday morning flight 666 | dallas to houston after 1201 am flight 667 | houston to dallas before midnight flight 668 | indianapolis to orlando december twenty seventh flight 669 | cheapest fare from indianapolis to orlando on the twenty seventh of december airfare 670 | cheapest fare round trip from indianapolis to orlando on december twenty seventh airfare 671 | cleveland to miami on wednesday arriving before 4 pm flight 672 | miami to cleveland sunday afternoon flight 673 | new york city to las vegas and memphis to las vegas on sunday flight 674 | new york to las vegas sunday afternoon flight 675 | memphis to las vegas sunday afternoon flight 676 | new york to las vegas on sunday afternoon flight 677 | chicago to seattle saturday morning flight 678 | chicago to las vegas saturday morning flight 679 | los angeles to pittsburgh afternoon tuesday flight 680 | los angeles to pittsburgh afternoon on monday flight 681 | pittsburgh to los angeles thursday evening flight 682 | milwaukee to phoenix on saturday flight 683 | phoenix to milwaukee on sunday flight 684 | phoenix to milwaukee on wednesday flight 685 | a flight from baltimore to san francisco arriving between 5 and 8 pm flight 686 | how many northwest flights leave st. paul flight 687 | how many northwest flights leave washington dc flight 688 | how many flights does northwest have leaving dulles flight 689 | what cities does northwest fly out of city 690 | list the cities from which northwest flies city 691 | what cities does northwest fly to city 692 | i would like a connecting flight from dallas to san francisco leaving after 4 o'clock flight 693 | please list all the flights from dallas to san francisco flight 694 | tell me again the morning flights on american airlines from philadelphia to dallas flight 695 | tell me the flights that leave philadelphia and go to dallas flight 696 | what is a d9s abbreviation 697 | what type of plane is a d9s aircraft 698 | show me the airports serviced by tower air airport 699 | show me the first class and coach flights between jfk and orlando flight 700 | show me the first class and coach flights from kennedy airport to miami flight 701 | show me the first class and coach flights from jfk to miami flight 702 | are meals ever served on tower air meal 703 | are snacks served on tower air meal 704 | show delta airlines flights from jfk to miami flight 705 | show delta airlines from boston to salt lake flight 706 | show delta airlines flights from boston to salt lake flight 707 | show delta airlines flights from boston to salt lake city flight 708 | what are the fares for flights between boston and washington dc airfare 709 | what is the least expensive fare from boston to salt lake city airfare 710 | what are the lowest fares from washington dc to salt lake city airfare 711 | what is the lowest fare from bwi to salt lake city airfare 712 | show me the cost of a first class ticket from detroit to las vegas and back airfare 713 | what is the earliest arriving flight from boston to washington dc flight 714 | what is the earliest arriving flight between boston and washington dc flight 715 | what 's the earliest arriving flight between boston and washington dc flight 716 | what is the earliest arriving flight from houston to orlando flight 717 | show me the flights between houston and orlando flight 718 | list all flights leaving denver between 8 pm and 9 pm flight 719 | what is the seating capacity on the aircraft 733 capacity 720 | what is the seating capacity of a 72s capacity 721 | what is the seating capacity of the aircraft 72s capacity 722 | what is the seating capacity of the aircraft m80 capacity 723 | what is the seating capacity of the type of aircraft m80 capacity 724 | what is the seating capacity of an m80 capacity 725 | what airlines serve denver airline 726 | list the airlines with flights to or from denver airline 727 | what airlines fly into denver airline 728 | list all flights arriving in denver between 8 and 9 pm flight 729 | what is the capacity of the 73s capacity 730 | what is 73s abbreviation 731 | what is seating capacity on the aircraft 73s capacity 732 | what is the seating capacity of a 757 capacity 733 | how many people will a 757 hold capacity 734 | how many passengers can fly on a 757 capacity 735 | list all of the daily flights arriving in denver between 8 and 9 pm flight 736 | list all of the daily flights arriving in denver from 8 to 9 pm flight 737 | show me all of the daily flights arriving in denver between 8 pm and 9 pm flight 738 | what is the seating capacity of the 757 capacity 739 | tell me about the m80 aircraft aircraft 740 | tell me about the type of aircraft called an m80 aircraft 741 | what is the seating capacity of the 733 capacity 742 | what is the seating capacity of the m80 capacity 743 | what is the seating capacity on the aircraft m80 capacity 744 | list all flights arriving or leaving denver between 8 and 9 pm flight 745 | list all flights on all types of aircraft arriving in denver between 8 and 9 pm flight 746 | please list all flights from nashville to memphis on monday morning flight 747 | please list the flights from nashville to memphis on monday morning flight 748 | is there ground transportation from the memphis airport into town when if i arrive at 842 in the morning ground_service 749 | please list the flights from memphis to new york city on a monday night flight 750 | what is cvg abbreviation 751 | what ground transportation is available from la guardia airport into new york city ground_service 752 | is there ground transportation from lga into new york city ground_service 753 | please list the ground transportation from lga into new york city ground_service 754 | please list ground transportation from ewr into new york city ground_service 755 | show me the morning flights from memphis to new york city flight 756 | give me the flights from new york city to nashville leaving after 5 pm on wednesday flight 757 | tell me about the ground transportation from nashville airport ground_service 758 | what are the nonstop flights from cincinnati to charlotte leaving after noon and arriving before 7 pm flight 759 | how many flights does alaska airlines have to burbank flight 760 | list the alaska airline flights from burbank to anywhere flight 761 | list the alaska airline flights from burbank flight 762 | which airline is as airline 763 | list the alaska airlines flights arriving in burbank flight 764 | list the alaska airlines flights a departing from burbank flight 765 | list all alaska airlines flights flight 766 | list all flights departing from seattle flight 767 | list the flights from indianapolis to memphis that leave before noon flight 768 | list the cheapest fare from charlotte to las vegas airfare 769 | i want a flight from los angeles to charlotte early in the morning flight 770 | i would like a morning flight from charlotte to newark flight 771 | i 'd like a morning flight from newark to los angeles flight 772 | i 'd like an evening flight from newark to los angeles flight 773 | i would like a flight that leaves on sunday from montreal quebec to san diego california flight 774 | i would like a flight on tuesday which leaves from san diego to indianapolis indiana and that leaves in the afternoon flight 775 | i would like to leave thursday morning from indianapolis to toronto flight 776 | i would like a flight on friday morning from toronto to montreal flight 777 | i would like a flight from cincinnati to burbank on american flight 778 | what type of aircraft is used for the american flight leaving at 419 pm aircraft 779 | i need a flight leaving kansas city to chicago leaving next wednesday and returning the following day flight 780 | what flights go from long beach to st. louis flight 781 | what are the flights from memphis to las vegas flight 782 | what are the flights from las vegas to ontario flight 783 | what are the flights from ontario to memphis flight 784 | what type of ground transportation is there at the las vegas airport ground_service 785 | is there taxi service at the ontario airport ground_service 786 | what are the flights from tampa to milwaukee flight 787 | what are the flights from milwaukee to seattle flight 788 | what are the flights from la guardia to san jose on united flight 789 | what are the flights on mondays that travel from charlotte north carolina to phoenix arizona flight 790 | what are the flights from phoenix arizona to st. paul minnesota on tuesday flight 791 | what are the flights on thursday leaving from st. paul minnesota to st. louis flight 792 | what are the flights from st. louis to charlotte north carolina leaving on friday flight 793 | what are the flights from boston to orlando that stop in new york flight 794 | i need a morning flight from burbank to milwaukee on next monday flight 795 | how about a flight from milwaukee to st. louis that leaves monday night flight 796 | and a flight from st. louis to burbank that leaves tuesday afternoon flight 797 | how about a flight leaving tuesday night from st. louis to burbank flight 798 | i need a flight from salt lake to newark airport that arrives on saturday before 6 pm flight 799 | i 'd like a flight from cincinnati to newark airport that arrives on saturday before 6 pm flight 800 | i need a flight on american airlines from miami to chicago that arrives around 5 pm flight 801 | i need a flight from memphis to tacoma that goes through los angeles flight 802 | what are the flights between cincinnati and san jose california which leave after 6 pm flight 803 | what are the nonstop flights between san jose and houston texas flight 804 | what are the nonstop flights between houston and memphis flight 805 | what are the flights between memphis and cincinnati on wednesday flight 806 | what are the american flights from newark to nashville flight 807 | the flights from ontario to westchester that stop in chicago flight 808 | please list the flights from los angeles to charlotte flight 809 | please list the flights from charlotte to newark flight 810 | please list the flights from newark to los angeles flight 811 | please list the flights from cincinnati to burbank on american airlines flight 812 | please give me the flights from kansas city to chicago on june sixteenth flight 813 | please give me the flights from chicago to kansas city on june seventeenth flight 814 | please list all the flights from kansas city to chicago on june sixteenth flight 815 | please list all the flights from chicago to kansas city on june seventeenth flight 816 | i 'd like to travel from burbank to milwaukee flight 817 | can you find me a flight from salt lake city to new york city next saturday before arriving before 6 pm flight 818 | can you find me another flight from cincinnati to new york on saturday before 6 pm flight 819 | can you list all of the delta flights from salt lake city to new york next saturday arriving before 6 pm flight 820 | i 'd like to fly from miami to chicago on on american airlines arriving around 5 pm flight 821 | i 'd like to travel from kansas city to chicago next wednesday flight 822 | i 'd like a round trip flight from kansas city to chicago on wednesday may twenty sixth arriving at 7 pm flight 823 | yes i 'd like to find a flight from memphis to tacoma stopping in los angeles flight 824 | find flight from san diego to phoenix on monday am flight 825 | find flight from phoenix to detroit on monday flight 826 | find flight from detroit to san diego on tuesday flight 827 | find flight from cincinnati to san jose on monday flight 828 | find flight from san jose to houston on wednesday flight 829 | find flight from houston to memphis on friday flight 830 | find flight from memphis to cincinnati on sunday flight 831 | find american flight from newark to nashville around 630 pm flight 832 | please find a flight round trip from los angeles to tacoma washington with a stopover in san francisco not exceeding the price of 300 dollars for june tenth 1993 flight 833 | are there any flights on june tenth from burbank to tacoma flight 834 | please find a flight from ontario to westchester that makes a stop in chicago on may seventeenth one way with dinner flight 835 | like to book a flight from burbank to milwaukee flight 836 | show me all the flights from burbank to milwaukee flight 837 | find me all the flights from milwaukee to st. louis flight 838 | now show me all the flights from st. louis to burbank flight 839 | is there one airline that flies from burbank to milwaukee milwaukee to st. louis and from st. louis to burbank airline 840 | find me all the round trip flights from burbank to milwaukee stopping in st. louis flight 841 | i 'd like to book two flights to westchester county flight 842 | i want to book a flight from salt lake city to westchester county flight 843 | tell me all the airports near westchester county airport 844 | i 'd like to book a flight from cincinnati to new york city on united airlines for next saturday flight 845 | tell me all the airports in the new york city area airport 846 | please find all the flights from cincinnati to any airport in the new york city area that arrive next saturday before 6 pm flight 847 | find me a flight from cincinnati to any airport in the new york city area flight 848 | i 'd like to fly from miami to chicago on american airlines flight 849 | i would like to book a round trip flight from kansas city to chicago flight 850 | find me a flight that flies from memphis to tacoma flight -------------------------------------------------------------------------------- /data/train_ext.tsv: -------------------------------------------------------------------------------- 1 | Can you tell me about the meal options on American Airlines flight 123? meal 2 | Do I need to pre-order a meal for my upcoming United Airlines flight from New York to Miami? meal 3 | What's the meal policy on Southwest Airlines flights from Denver to Las Vegas? meal 4 | Tell me if there are any vegetarian meal choices on Delta flight 456 from Seattle to Orlando. meal 5 | Are there gluten-free meal options on Alaska Airlines flights to San Diego from San Francisco? meal 6 | I'm flying from Houston to Phoenix on US Airways. Can I see the menu for in-flight meals? meal 7 | Is there a special meal service for passengers with dietary restrictions on JetBlue flights? meal 8 | What's the cost of purchasing a meal on my Spirit Airlines flight from Las Vegas to Chicago? meal 9 | Can you provide information about the breakfast options on early morning flights to New York? meal 10 | I have a long-haul flight from Los Angeles to Tokyo. What are the meal choices for business class? meal 11 | Can you tell me the baggage policy for international flights from New York to London? restriction 12 | What are the baggage weight limits for flights from Los Angeles to Tokyo on economy tickets? restriction 13 | I need to know the restrictions on booking a flight for two adults and one child from Miami to Cancun. restriction 14 | Are there any restrictions on the refund policy for flights to Las Vegas from Denver? restriction 15 | What is the cancellation policy for flight AF123 from Paris to New York? restriction 16 | What's the restriction for booking a flight with a pet from Seattle to Miami? restriction 17 | Can you explain the restrictions on the discount code DC456 for flights to Orlando? restriction 18 | What's the policy for booking a flight from San Francisco to New York with a lap infant? restriction 19 | What is the fare restriction code for a first-class ticket from New York to Los Angeles? restriction 20 | I'd like to know the restrictions for changing a flight booking from Dallas to Chicago. restriction 21 | What's the least expensive option available? cheapest 22 | I'm looking for the most affordable fare. cheapest 23 | "Find me the lowest-priced ticket, please." cheapest 24 | Can you show me the cheapest flight deal? cheapest 25 | I want the cheapest possible booking. cheapest 26 | Please display the least costly fare. cheapest 27 | Looking for the best bargain on a flight. cheapest 28 | What's the cheapest rate for this route? cheapest 29 | Show me the flights with the lowest prices. cheapest 30 | I need information on the cheapest option. cheapest -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '1' 2 | services: 3 | my-roberta-app: 4 | image: my-roberta-app 5 | restart: always 6 | ports: 7 | - 8080:8080 8 | expose: 9 | - 8080 10 | volumes: 11 | - .:/app 12 | command: ["python3", "server.py", "--model", "xlm-roberta-large-custom-trained"] -------------------------------------------------------------------------------- /intent_classifier.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from roberta import Roberta 3 | 4 | 5 | class IntentClassifier: 6 | def __init__(self): 7 | self.model_loaded = False 8 | self.model = Roberta() 9 | 10 | def is_ready(self): 11 | return self.model_loaded if self.model_loaded else False 12 | 13 | def load(self, file_path): 14 | self.model_loaded = self.model.load(file_path) 15 | 16 | def classify_intent_function(self, text): 17 | return self.model.inference(text) 18 | 19 | 20 | if __name__ == '__main__': 21 | model = IntentClassifier() 22 | model.load("xlm-roberta-large-custom-trained") 23 | print(model.is_ready()) 24 | -------------------------------------------------------------------------------- /notebooks/Train.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 27, 6 | "metadata": { 7 | "id": "UeQRmpGcXj7r" 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "!pip install scikit-learn scipy flask pandas -q\n", 12 | "!pip install torch sentencepiece transformers -q" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 8, 18 | "metadata": { 19 | "id": "GUcUOTYGW41V" 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "import os\n", 24 | "import torch\n", 25 | "import pandas as pd\n", 26 | "from sklearn.model_selection import train_test_split\n", 27 | "from sklearn.model_selection import StratifiedKFold\n", 28 | "from sklearn.metrics import classification_report\n", 29 | "from sklearn.preprocessing import LabelEncoder\n", 30 | "from transformers import XLMRobertaTokenizer, XLMRobertaForSequenceClassification, Trainer, TrainingArguments" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 9, 36 | "metadata": { 37 | "id": "JNDMPEg_xEeq" 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "#setup work directories\n", 42 | "current_directory = os.getcwd()\n", 43 | "\n", 44 | "workdir = os.path.dirname(current_directory) + \"/\"\n", 45 | "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", 46 | "model_name = \"xlm-roberta-large\"\n", 47 | "model_path = workdir + f\"{model_name}-custom-trained\" # Save the trained model if needed\n", 48 | "cache_dir = workdir + \"model_cache\"\n", 49 | "\n", 50 | "#training data\n", 51 | "train_file_path = workdir + \"data/train.tsv\"\n", 52 | "train_ext_path = workdir + \"data/train_ext.tsv\"" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 10, 58 | "metadata": { 59 | "id": "6cxVkBc4z8sO" 60 | }, 61 | "outputs": [], 62 | "source": [ 63 | "# Define training parameters\n", 64 | "epochs = 6\n", 65 | "batch_size = 4" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 11, 71 | "metadata": { 72 | "colab": { 73 | "base_uri": "https://localhost:8080/" 74 | }, 75 | "id": "x_BvjFncW-BZ", 76 | "outputId": "6b5e3478-6c04-4a7f-a8f9-b518569ff022" 77 | }, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "Number of examples in training file: 4634\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "# Load training data from TSV file\n", 89 | "data = pd.read_csv(train_file_path, delimiter=\"\\t\", names = [\"text\", \"label\"])\n", 90 | "print(\"Number of examples in training file:\",len(data))" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 12, 96 | "metadata": { 97 | "colab": { 98 | "base_uri": "https://localhost:8080/", 99 | "height": 206 100 | }, 101 | "id": "Z1NXEIiEYQ-1", 102 | "outputId": "dde3de78-af2e-4732-b614-a3bb0985b345" 103 | }, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/html": [ 108 | "
\n", 109 | "\n", 122 | "\n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | "
labelcount
2aircraft+flight+flight_no1
18ground_service+ground_fare1
4airfare+flight_time1
9cheapest1
6airline+flight_no2
\n", 158 | "
" 159 | ], 160 | "text/plain": [ 161 | " label count\n", 162 | "2 aircraft+flight+flight_no 1\n", 163 | "18 ground_service+ground_fare 1\n", 164 | "4 airfare+flight_time 1\n", 165 | "9 cheapest 1\n", 166 | "6 airline+flight_no 2" 167 | ] 168 | }, 169 | "execution_count": 12, 170 | "metadata": {}, 171 | "output_type": "execute_result" 172 | } 173 | ], 174 | "source": [ 175 | "#count of different classes' examples.\n", 176 | "aggregate_data = data.groupby('label').size().reset_index(name='count').sort_values(['count'], ascending=True)\n", 177 | "aggregate_data.head()" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": { 183 | "id": "q0ii77SIBhqn" 184 | }, 185 | "source": [ 186 | "### Split the multiple intent joined by + into multiple rows" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 13, 192 | "metadata": { 193 | "colab": { 194 | "base_uri": "https://localhost:8080/" 195 | }, 196 | "id": "YNmkN2jCBjSa", 197 | "outputId": "db203e29-5f80-4f65-b2f6-d5b20e689bd7" 198 | }, 199 | "outputs": [ 200 | { 201 | "data": { 202 | "text/plain": [ 203 | "4657" 204 | ] 205 | }, 206 | "execution_count": 13, 207 | "metadata": {}, 208 | "output_type": "execute_result" 209 | } 210 | ], 211 | "source": [ 212 | "df_split = data[data['label'].str.contains(r'\\+', regex=True)].copy()\n", 213 | "df_split['label'] = df_split['label'].str.split('+')\n", 214 | "\n", 215 | "# Expand the list of intents into separate rows\n", 216 | "df_split = df_split.explode('label')\n", 217 | "\n", 218 | "# Remove the original rows with '+' sign\n", 219 | "data = data[~data['label'].str.contains(r'\\+', regex=True)]\n", 220 | "\n", 221 | "# Concatenate the split DataFrame with the original DataFrame\n", 222 | "data = pd.concat([data, df_split], ignore_index=True)\n", 223 | "len(data)" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 14, 229 | "metadata": { 230 | "colab": { 231 | "base_uri": "https://localhost:8080/", 232 | "height": 206 233 | }, 234 | "id": "jOSLddtbBnr3", 235 | "outputId": "6b1ff7f2-6a16-4bcf-9844-29cfeb27c77a" 236 | }, 237 | "outputs": [ 238 | { 239 | "data": { 240 | "text/html": [ 241 | "
\n", 242 | "\n", 255 | "\n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | "
labelcount
6cheapest1
16restriction5
14meal6
10flight_no15
5capacity16
\n", 291 | "
" 292 | ], 293 | "text/plain": [ 294 | " label count\n", 295 | "6 cheapest 1\n", 296 | "16 restriction 5\n", 297 | "14 meal 6\n", 298 | "10 flight_no 15\n", 299 | "5 capacity 16" 300 | ] 301 | }, 302 | "execution_count": 14, 303 | "metadata": {}, 304 | "output_type": "execute_result" 305 | } 306 | ], 307 | "source": [ 308 | "#count of different classes' examples.\n", 309 | "aggregate_data = data.groupby('label').size().reset_index(name='count').sort_values(['count'], ascending=True)\n", 310 | "aggregate_data.head()" 311 | ] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "metadata": { 316 | "id": "WxqoWfgoSaB0" 317 | }, 318 | "source": [ 319 | "### Data augmentation\n", 320 | "In some categories, the dataset has a limited number of examples.\n", 321 | "To address this, we'll augment the dataset by generating synthetic examples using ChatGPT.\n", 322 | "These generated examples will be saved in the 'train_ext.tsv' file." 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 15, 328 | "metadata": { 329 | "colab": { 330 | "base_uri": "https://localhost:8080/" 331 | }, 332 | "id": "SDNS5MmWgcM5", 333 | "outputId": "825beba6-0004-4cf6-d200-3764b871c06c" 334 | }, 335 | "outputs": [ 336 | { 337 | "data": { 338 | "text/plain": [ 339 | "30" 340 | ] 341 | }, 342 | "execution_count": 15, 343 | "metadata": {}, 344 | "output_type": "execute_result" 345 | } 346 | ], 347 | "source": [ 348 | "data_ext = pd.read_csv(train_ext_path, delimiter=\"\\t\", names = [\"text\", \"label\"])\n", 349 | "len(data_ext)" 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "execution_count": 16, 355 | "metadata": { 356 | "id": "Kc1-oxdDDKlK" 357 | }, 358 | "outputs": [], 359 | "source": [ 360 | "data = pd.concat([data, data_ext], ignore_index=True)" 361 | ] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "execution_count": 17, 366 | "metadata": { 367 | "colab": { 368 | "base_uri": "https://localhost:8080/", 369 | "height": 206 370 | }, 371 | "id": "-Ab0ReilDeLr", 372 | "outputId": "a490fa4c-e678-4c23-cf75-6e700412d1df" 373 | }, 374 | "outputs": [ 375 | { 376 | "data": { 377 | "text/html": [ 378 | "
\n", 379 | "\n", 392 | "\n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | "
labelcount
6cheapest11
16restriction15
10flight_no15
14meal16
5capacity16
\n", 428 | "
" 429 | ], 430 | "text/plain": [ 431 | " label count\n", 432 | "6 cheapest 11\n", 433 | "16 restriction 15\n", 434 | "10 flight_no 15\n", 435 | "14 meal 16\n", 436 | "5 capacity 16" 437 | ] 438 | }, 439 | "execution_count": 17, 440 | "metadata": {}, 441 | "output_type": "execute_result" 442 | } 443 | ], 444 | "source": [ 445 | "#count of different classes' examples.\n", 446 | "aggregate_data = data.groupby('label').size().reset_index(name='count').sort_values(['count'], ascending=True)\n", 447 | "aggregate_data.head()" 448 | ] 449 | }, 450 | { 451 | "cell_type": "markdown", 452 | "metadata": {}, 453 | "source": [ 454 | "### Training" 455 | ] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": 18, 460 | "metadata": { 461 | "colab": { 462 | "base_uri": "https://localhost:8080/" 463 | }, 464 | "id": "a6dytmOYdU7s", 465 | "outputId": "40c83e8d-a5d8-4e34-95ea-aac6f566d952" 466 | }, 467 | "outputs": [ 468 | { 469 | "ename": "KeyboardInterrupt", 470 | "evalue": "", 471 | "output_type": "error", 472 | "traceback": [ 473 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 474 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 475 | "Cell \u001b[0;32mIn[18], line 41\u001b[0m\n\u001b[1;32m 38\u001b[0m class_weights_tensor \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mtensor(class_weights, dtype\u001b[38;5;241m=\u001b[39mtorch\u001b[38;5;241m.\u001b[39mfloat32)\u001b[38;5;241m.\u001b[39mto(device)\n\u001b[1;32m 40\u001b[0m \u001b[38;5;66;03m# Initialize the model\u001b[39;00m\n\u001b[0;32m---> 41\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mXLMRobertaForSequenceClassification\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum_labels\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mlabel_encoder\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclasses_\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mto(device)\n\u001b[1;32m 42\u001b[0m optimizer \u001b[38;5;241m=\u001b[39m AdamW(model\u001b[38;5;241m.\u001b[39mparameters(), lr\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1e-5\u001b[39m)\n\u001b[1;32m 43\u001b[0m \u001b[38;5;66;03m# loss_fn = torch.nn.CrossEntropyLoss()\u001b[39;00m\n", 476 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/transformers/modeling_utils.py:2876\u001b[0m, in \u001b[0;36mPreTrainedModel.from_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 2873\u001b[0m init_contexts\u001b[38;5;241m.\u001b[39mappend(init_empty_weights())\n\u001b[1;32m 2875\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m ContextManagers(init_contexts):\n\u001b[0;32m-> 2876\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mmodel_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mmodel_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2878\u001b[0m \u001b[38;5;66;03m# Check first if we are `from_pt`\u001b[39;00m\n\u001b[1;32m 2879\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m use_keep_in_fp32_modules:\n", 477 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/transformers/models/xlm_roberta/modeling_xlm_roberta.py:1171\u001b[0m, in \u001b[0;36mXLMRobertaForSequenceClassification.__init__\u001b[0;34m(self, config)\u001b[0m\n\u001b[1;32m 1168\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_labels \u001b[38;5;241m=\u001b[39m config\u001b[38;5;241m.\u001b[39mnum_labels\n\u001b[1;32m 1169\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig \u001b[38;5;241m=\u001b[39m config\n\u001b[0;32m-> 1171\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mroberta \u001b[38;5;241m=\u001b[39m \u001b[43mXLMRobertaModel\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43madd_pooling_layer\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 1172\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclassifier \u001b[38;5;241m=\u001b[39m XLMRobertaClassificationHead(config)\n\u001b[1;32m 1174\u001b[0m \u001b[38;5;66;03m# Initialize weights and apply final processing\u001b[39;00m\n", 478 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/transformers/models/xlm_roberta/modeling_xlm_roberta.py:714\u001b[0m, in \u001b[0;36mXLMRobertaModel.__init__\u001b[0;34m(self, config, add_pooling_layer)\u001b[0m\n\u001b[1;32m 711\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(config)\n\u001b[1;32m 712\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig \u001b[38;5;241m=\u001b[39m config\n\u001b[0;32m--> 714\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39membeddings \u001b[38;5;241m=\u001b[39m \u001b[43mXLMRobertaEmbeddings\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 715\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mencoder \u001b[38;5;241m=\u001b[39m XLMRobertaEncoder(config)\n\u001b[1;32m 717\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpooler \u001b[38;5;241m=\u001b[39m XLMRobertaPooler(config) \u001b[38;5;28;01mif\u001b[39;00m add_pooling_layer \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n", 479 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/transformers/models/xlm_roberta/modeling_xlm_roberta.py:74\u001b[0m, in \u001b[0;36mXLMRobertaEmbeddings.__init__\u001b[0;34m(self, config)\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, config):\n\u001b[1;32m 73\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m()\n\u001b[0;32m---> 74\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mword_embeddings \u001b[38;5;241m=\u001b[39m \u001b[43mnn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mEmbedding\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvocab_size\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhidden_size\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpadding_idx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpad_token_id\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 75\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mposition_embeddings \u001b[38;5;241m=\u001b[39m nn\u001b[38;5;241m.\u001b[39mEmbedding(config\u001b[38;5;241m.\u001b[39mmax_position_embeddings, config\u001b[38;5;241m.\u001b[39mhidden_size)\n\u001b[1;32m 76\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtoken_type_embeddings \u001b[38;5;241m=\u001b[39m nn\u001b[38;5;241m.\u001b[39mEmbedding(config\u001b[38;5;241m.\u001b[39mtype_vocab_size, config\u001b[38;5;241m.\u001b[39mhidden_size)\n", 480 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/torch/nn/modules/sparse.py:144\u001b[0m, in \u001b[0;36mEmbedding.__init__\u001b[0;34m(self, num_embeddings, embedding_dim, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse, _weight, _freeze, device, dtype)\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m _weight \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 142\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mweight \u001b[38;5;241m=\u001b[39m Parameter(torch\u001b[38;5;241m.\u001b[39mempty((num_embeddings, embedding_dim), \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mfactory_kwargs),\n\u001b[1;32m 143\u001b[0m requires_grad\u001b[38;5;241m=\u001b[39m\u001b[38;5;129;01mnot\u001b[39;00m _freeze)\n\u001b[0;32m--> 144\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreset_parameters\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 145\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 146\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mlist\u001b[39m(_weight\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;241m==\u001b[39m [num_embeddings, embedding_dim], \\\n\u001b[1;32m 147\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mShape of weight does not match num_embeddings and embedding_dim\u001b[39m\u001b[38;5;124m'\u001b[39m\n", 481 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/torch/nn/modules/sparse.py:153\u001b[0m, in \u001b[0;36mEmbedding.reset_parameters\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 152\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mreset_parameters\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 153\u001b[0m \u001b[43minit\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnormal_\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mweight\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fill_padding_idx_with_zero()\n", 482 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/torch/nn/init.py:155\u001b[0m, in \u001b[0;36mnormal_\u001b[0;34m(tensor, mean, std)\u001b[0m\n\u001b[1;32m 153\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m torch\u001b[38;5;241m.\u001b[39moverrides\u001b[38;5;241m.\u001b[39mhas_torch_function_variadic(tensor):\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m torch\u001b[38;5;241m.\u001b[39moverrides\u001b[38;5;241m.\u001b[39mhandle_torch_function(normal_, (tensor,), tensor\u001b[38;5;241m=\u001b[39mtensor, mean\u001b[38;5;241m=\u001b[39mmean, std\u001b[38;5;241m=\u001b[39mstd)\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_no_grad_normal_\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtensor\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmean\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstd\u001b[49m\u001b[43m)\u001b[49m\n", 483 | "File \u001b[0;32m~/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/torch/nn/init.py:19\u001b[0m, in \u001b[0;36m_no_grad_normal_\u001b[0;34m(tensor, mean, std)\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_no_grad_normal_\u001b[39m(tensor, mean, std):\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m torch\u001b[38;5;241m.\u001b[39mno_grad():\n\u001b[0;32m---> 19\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mtensor\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnormal_\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmean\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstd\u001b[49m\u001b[43m)\u001b[49m\n", 484 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: " 485 | ] 486 | } 487 | ], 488 | "source": [ 489 | "import torch\n", 490 | "import numpy as np\n", 491 | "import pickle\n", 492 | "from transformers import XLMRobertaTokenizer, XLMRobertaForSequenceClassification, AdamW\n", 493 | "from torch.utils.data import DataLoader, TensorDataset\n", 494 | "from sklearn.preprocessing import LabelEncoder\n", 495 | "from sklearn.metrics import accuracy_score\n", 496 | "from sklearn.utils.class_weight import compute_class_weight\n", 497 | "\n", 498 | "# Load the XLM-RoBERTa tokenizer\n", 499 | "tokenizer = XLMRobertaTokenizer.from_pretrained(model_name, cache_dir=cache_dir)\n", 500 | "\n", 501 | "# Example data (replace with your own dataset)\n", 502 | "texts = data.text.tolist()\n", 503 | "labels = data.label.tolist() # String labels\n", 504 | "\n", 505 | "# Encode the string labels to integers\n", 506 | "label_encoder = LabelEncoder()\n", 507 | "encoded_labels = label_encoder.fit_transform(labels)\n", 508 | "\n", 509 | "# Tokenize the texts\n", 510 | "encoded_texts = tokenizer(texts, padding=True, truncation=True, return_tensors=\"pt\")\n", 511 | "\n", 512 | "# Create DataLoader from the tokenized data\n", 513 | "dataset = TensorDataset(\n", 514 | " encoded_texts[\"input_ids\"],\n", 515 | " encoded_texts[\"attention_mask\"],\n", 516 | " torch.tensor(encoded_labels, dtype=torch.long),\n", 517 | ")\n", 518 | "\n", 519 | "# Create a DataLoader for the entire dataset\n", 520 | "dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True)\n", 521 | "\n", 522 | "# Compute class weights\n", 523 | "class_weights = compute_class_weight('balanced', classes=np.unique(encoded_labels), y=encoded_labels)\n", 524 | "\n", 525 | "# Convert class weights to a PyTorch tensor\n", 526 | "class_weights_tensor = torch.tensor(class_weights, dtype=torch.float32).to(device)\n", 527 | "\n", 528 | "# Initialize the model\n", 529 | "model = XLMRobertaForSequenceClassification.from_pretrained(model_name, num_labels=len(label_encoder.classes_), cache_dir=cache_dir).to(device)\n", 530 | "optimizer = AdamW(model.parameters(), lr=1e-5)\n", 531 | "# loss_fn = torch.nn.CrossEntropyLoss()\n", 532 | "\n", 533 | "loss_fn = torch.nn.CrossEntropyLoss(weight=class_weights_tensor)\n", 534 | "\n", 535 | "# Training loop\n", 536 | "for epoch in range(epochs):\n", 537 | " model.train()\n", 538 | " total_loss = 0\n", 539 | " all_labels = []\n", 540 | " all_predictions = []\n", 541 | "\n", 542 | " for batch in dataloader:\n", 543 | " input_ids, attention_mask, labels = batch\n", 544 | " input_ids, attention_mask, labels = input_ids.to(device), attention_mask.to(device), labels.to(device)\n", 545 | "\n", 546 | " optimizer.zero_grad()\n", 547 | "\n", 548 | " outputs = model(input_ids, attention_mask=attention_mask, labels=labels)\n", 549 | " loss = outputs.loss\n", 550 | " total_loss += loss.item()\n", 551 | "\n", 552 | " loss.backward()\n", 553 | " optimizer.step()\n", 554 | "\n", 555 | " _, predicted = torch.max(outputs.logits, 1)\n", 556 | " all_labels.extend(labels.cpu().numpy())\n", 557 | " all_predictions.extend(predicted.cpu().numpy())\n", 558 | "\n", 559 | " avg_loss = total_loss / len(dataloader)\n", 560 | " accuracy = accuracy_score(all_labels, all_predictions)\n", 561 | "\n", 562 | " print(f\"Epoch {epoch+1}/{epochs}, Training Loss: {avg_loss:.4f}, Training Accuracy: {accuracy:.4f}\")\n", 563 | "\n", 564 | "model.save_pretrained(model_path)\n", 565 | "\n", 566 | "# Save label encoder for inference\n", 567 | "with open(model_path + \"/label_encoder.pkl\", \"wb\") as le_file:\n", 568 | " pickle.dump(label_encoder, le_file)" 569 | ] 570 | }, 571 | { 572 | "cell_type": "markdown", 573 | "metadata": { 574 | "id": "iY8-DX8YN6pR" 575 | }, 576 | "source": [ 577 | "### Evaluation" 578 | ] 579 | }, 580 | { 581 | "cell_type": "code", 582 | "execution_count": 20, 583 | "metadata": { 584 | "colab": { 585 | "base_uri": "https://localhost:8080/" 586 | }, 587 | "id": "gFg51X4IrxQa", 588 | "outputId": "e27ceb71-5185-4aaf-d420-c16c561f5aec" 589 | }, 590 | "outputs": [ 591 | { 592 | "name": "stdout", 593 | "output_type": "stream", 594 | "text": [ 595 | "[{'label': 'cheapest', 'confidence': '0.9677'}, {'label': 'airfare', 'confidence': '0.0081'}, {'label': 'flight', 'confidence': '0.0060'}]\n" 596 | ] 597 | }, 598 | { 599 | "name": "stderr", 600 | "output_type": "stream", 601 | "text": [ 602 | "/Users/b0268760/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/sklearn/base.py:347: InconsistentVersionWarning: Trying to unpickle estimator LabelEncoder from version 1.2.2 when using version 1.3.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n", 603 | "https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n", 604 | " warnings.warn(\n" 605 | ] 606 | } 607 | ], 608 | "source": [ 609 | "import torch\n", 610 | "import pickle\n", 611 | "from transformers import XLMRobertaTokenizer, XLMRobertaForSequenceClassification\n", 612 | "from sklearn.preprocessing import LabelEncoder\n", 613 | "from sklearn.metrics import precision_score, recall_score, f1_score\n", 614 | "\n", 615 | "# Load the tokenizer and model\n", 616 | "tokenizer = XLMRobertaTokenizer.from_pretrained(model_name)\n", 617 | "model = XLMRobertaForSequenceClassification.from_pretrained(model_path)\n", 618 | "model.to(device)\n", 619 | "\n", 620 | "# Load the label encoder from the file\n", 621 | "with open(model_path+\"/label_encoder.pkl\", \"rb\") as le_file:\n", 622 | " label_encoder = pickle.load(le_file)\n", 623 | "\n", 624 | "\n", 625 | "def classify(input_text):\n", 626 | "\n", 627 | " # Tokenize the input text\n", 628 | " encoded_text = tokenizer(input_text, padding=True, truncation=True, return_tensors=\"pt\")\n", 629 | " encoded_text.to(device)\n", 630 | "\n", 631 | " # Perform inference\n", 632 | " with torch.no_grad():\n", 633 | " outputs = model(encoded_text.input_ids.to(device), attention_mask=encoded_text.attention_mask.to(device))\n", 634 | "\n", 635 | " predicted_probabilities = torch.softmax(outputs.logits, dim=1)\n", 636 | "\n", 637 | " # Get the top three predicted classes and their corresponding probabilities\n", 638 | " top_classes = torch.topk(predicted_probabilities, 3, dim=1)\n", 639 | " top_class_indices = top_classes.indices[0].tolist()\n", 640 | " top_class_probabilities = top_classes.values[0].tolist()\n", 641 | "\n", 642 | " # Map the class indices back to the original string labels using the label encoder\n", 643 | " top_class_labels = label_encoder.inverse_transform(top_class_indices)\n", 644 | "\n", 645 | " res = []\n", 646 | "\n", 647 | " for label, probability in zip(top_class_labels, top_class_probabilities):\n", 648 | " res.append({\"label\": label, \"confidence\": f\"{probability:.4f}\"})\n", 649 | " return res\n", 650 | "input_text = \"suggest cheapest flight tickets\"\n", 651 | "print(classify(input_text))" 652 | ] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": 21, 657 | "metadata": { 658 | "id": "js3zZ0atFJk2" 659 | }, 660 | "outputs": [], 661 | "source": [ 662 | "def evaluation(data):\n", 663 | " # Get the true labels for the test data\n", 664 | " true_labels = data.label\n", 665 | "\n", 666 | " # Make predictions using your inference function\n", 667 | " predicted_labels = data.text.apply(lambda x: classify(x)[0][\"label\"])\n", 668 | "\n", 669 | " # Calculate accuracy\n", 670 | " acc = accuracy_score(true_labels, predicted_labels)\n", 671 | " print(\"Accuracy:\", acc)\n", 672 | "\n", 673 | " # Calculate precision, recall, and F1 score\n", 674 | " precision = precision_score(true_labels, predicted_labels, average='weighted')\n", 675 | " recall = recall_score(true_labels, predicted_labels, average='weighted')\n", 676 | " f1 = f1_score(true_labels, predicted_labels, average='weighted')\n", 677 | "\n", 678 | " print(\"Precision :\", precision)\n", 679 | " print(\"Recall :\", recall)\n", 680 | " print(\"F1 Score:\", f1)" 681 | ] 682 | }, 683 | { 684 | "cell_type": "code", 685 | "execution_count": null, 686 | "metadata": { 687 | "colab": { 688 | "base_uri": "https://localhost:8080/" 689 | }, 690 | "id": "9uU5gwxCdUex", 691 | "outputId": "2f60b60d-94c2-445f-d53d-8c9c52bb70fa" 692 | }, 693 | "outputs": [], 694 | "source": [ 695 | "#train eval\n", 696 | "data = pd.read_csv(workdir+\"data/train.tsv\", delimiter=\"\\t\", names = [\"text\", \"label\"])\n", 697 | "evaluation(data)" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": 22, 703 | "metadata": { 704 | "colab": { 705 | "base_uri": "https://localhost:8080/" 706 | }, 707 | "id": "fvs495Y6ohsw", 708 | "outputId": "eab535e4-51b8-4120-e702-cef819e8983a" 709 | }, 710 | "outputs": [ 711 | { 712 | "name": "stdout", 713 | "output_type": "stream", 714 | "text": [ 715 | "Accuracy: 0.9705882352941176\n", 716 | "Precision : 0.9551627542402729\n", 717 | "Recall : 0.9705882352941176\n", 718 | "F1 Score: 0.9622531573499896\n" 719 | ] 720 | }, 721 | { 722 | "name": "stderr", 723 | "output_type": "stream", 724 | "text": [ 725 | "/Users/b0268760/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1469: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n", 726 | " _warn_prf(average, modifier, msg_start, len(result))\n", 727 | "/Users/b0268760/opt/anaconda3/envs/intent-detection-using-XLM-Roberta/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1469: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n", 728 | " _warn_prf(average, modifier, msg_start, len(result))\n" 729 | ] 730 | } 731 | ], 732 | "source": [ 733 | "#test eval\n", 734 | "test = pd.read_csv(workdir+\"data/test.tsv\", delimiter=\"\\t\", names = [\"text\", \"label\"])\n", 735 | "evaluation(test)" 736 | ] 737 | }, 738 | { 739 | "cell_type": "code", 740 | "execution_count": 20, 741 | "metadata": { 742 | "id": "5q3O8yhCDqN2" 743 | }, 744 | "outputs": [], 745 | "source": [] 746 | } 747 | ], 748 | "metadata": { 749 | "accelerator": "GPU", 750 | "colab": { 751 | "gpuType": "T4", 752 | "provenance": [] 753 | }, 754 | "kernelspec": { 755 | "display_name": "Python 3 (ipykernel)", 756 | "language": "python", 757 | "name": "python3" 758 | }, 759 | "language_info": { 760 | "codemirror_mode": { 761 | "name": "ipython", 762 | "version": 3 763 | }, 764 | "file_extension": ".py", 765 | "mimetype": "text/x-python", 766 | "name": "python", 767 | "nbconvert_exporter": "python", 768 | "pygments_lexer": "ipython3", 769 | "version": "3.10.13" 770 | } 771 | }, 772 | "nbformat": 4, 773 | "nbformat_minor": 4 774 | } 775 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | scikit-learn 2 | scipy 3 | flask 4 | sentencepiece 5 | huggingface-hub 6 | torch 7 | transformers 8 | -------------------------------------------------------------------------------- /roberta.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import pickle 3 | import os 4 | from transformers import XLMRobertaTokenizer, XLMRobertaForSequenceClassification 5 | 6 | # Check if CUDA (GPU) is available, otherwise use CPU 7 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 8 | 9 | 10 | # Define a class for working with the XLM-Roberta model 11 | class Roberta: 12 | def __init__(self): 13 | self.tokenizer = None 14 | self.model = None 15 | self.label_encoder = None 16 | 17 | def load(self, model_path): 18 | # Check if model files exist at the provided path 19 | if os.path.exists(os.path.join(model_path, "model.safetensors")): 20 | print(f"Loading model from local path: {model_path}") 21 | 22 | model_name = "-".join(model_path.split("-")[:3]) # Extract model name from path 23 | 24 | # Load model and tokenizer 25 | self.tokenizer = XLMRobertaTokenizer.from_pretrained(model_name) 26 | self.model = XLMRobertaForSequenceClassification.from_pretrained(model_path) 27 | 28 | else: 29 | model_name = "-".join(model_path.split("-")[:3]) # Extract model name from path 30 | print(f"Model files not found at {model_path}. Downloading from Hugging Face...") 31 | 32 | # Download model and tokenizer directly 33 | self.tokenizer = XLMRobertaTokenizer.from_pretrained(model_name) 34 | self.model = XLMRobertaForSequenceClassification.from_pretrained(model_name) 35 | 36 | # Save the downloaded model to the specified path 37 | self.model.save_pretrained(model_path) 38 | 39 | self.model.to(device) 40 | 41 | # Load the label encoder from the file 42 | self.label_encoder = pickle.load(open(model_path + "/label_encoder.pkl", "rb")) 43 | return True 44 | 45 | def inference(self, text, k=3): 46 | # Tokenize the input text 47 | encoded_text = self.tokenizer(text, padding=True, truncation=True, return_tensors="pt") 48 | encoded_text.to(device) 49 | 50 | # Perform inference 51 | with torch.no_grad(): 52 | outputs = self.model(encoded_text.input_ids.to(device), 53 | attention_mask=encoded_text.attention_mask.to(device)) 54 | predicted_probabilities = torch.softmax(outputs.logits, dim=1) 55 | 56 | # Get the top three predicted classes and their corresponding probabilities 57 | k = k if k <= predicted_probabilities.shape[1] else predicted_probabilities.shape[1] 58 | top_classes = torch.topk(predicted_probabilities, k, dim=1) 59 | top_class_indices = top_classes.indices[0].tolist() 60 | top_class_probabilities = top_classes.values[0].tolist() 61 | 62 | # Map the class indices back to the original string labels using the label encoder 63 | top_class_labels = self.label_encoder.inverse_transform(top_class_indices) 64 | 65 | res = [] 66 | 67 | # Prepare the result as a list of dictionaries 68 | for label, probability in zip(top_class_labels, top_class_probabilities): 69 | res.append({"label": label, "confidence": f"{probability:.4f}"}) 70 | return res 71 | 72 | 73 | if __name__ == '__main__': 74 | input_text = "suggest cheapest flight tickets" 75 | model = Roberta() 76 | model.load("xlm-roberta-large-custom-trained") 77 | print(model.inference(input_text)) 78 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import os 4 | import logging 5 | import argparse 6 | from flask import Flask, request, jsonify 7 | from intent_classifier import IntentClassifier 8 | 9 | app = Flask(__name__) 10 | model = IntentClassifier() 11 | 12 | logging.basicConfig(level=logging.INFO, filename='classifier.log', filemode='a') 13 | logger = logging.getLogger(__name__) 14 | log_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 15 | 16 | 17 | @app.route('/ready') 18 | def ready(): 19 | if model.is_ready(): 20 | return 'OK', 200 21 | else: 22 | return 'Not ready', 423 23 | 24 | 25 | @app.route('/intent', methods=['POST']) 26 | def intent(): 27 | try: 28 | # Check if the request has a JSON body 29 | if not request.json: 30 | return jsonify({"label": "BODY_MISSING", "message": "Request doesn't have a body."}), 400 31 | 32 | # Check if the 'text' field is present in the request JSON 33 | if 'text' not in request.json: 34 | return jsonify({"label": "TEXT_MISSING", "message": "\"text\" missing from request body."}), 400 35 | 36 | # Check if the 'text' field is a string 37 | if not isinstance(request.json['text'], str): 38 | return jsonify({"label": "INVALID_TYPE", "message": "\"text\" is not a string."}), 400 39 | 40 | # Check if the 'text' field is empty 41 | if not request.json['text'].strip(): 42 | return jsonify({"label": "TEXT_EMPTY", "message": "\"text\" is empty."}), 400 43 | 44 | # Perform intent classification (replace this with your actual intent classification logic) 45 | intents = model.classify_intent_function(request.json['text']) 46 | 47 | # Create a response with the top 3 intent predictions 48 | response = {"intents": intents[:3]} 49 | 50 | return jsonify(response) 51 | 52 | except Exception as e: 53 | logger.exception('Internal error: %s', str(e)) 54 | # Handle internal errors 55 | return jsonify({"label": "INTERNAL_ERROR", "message": str(e)}), 500 56 | 57 | 58 | def main(): 59 | arg_parser = argparse.ArgumentParser() 60 | arg_parser.add_argument('--model', type=str, required=True, help='Path to model directory or file.') 61 | arg_parser.add_argument('--port', type=int, default=os.getenv('PORT', 8080), help='Server port number.') 62 | args = arg_parser.parse_args() 63 | model.load(args.model) 64 | logger.info('Server is starting on port %s', args.port) 65 | app.run(port=args.port) 66 | 67 | 68 | if __name__ == '__main__': 69 | main() 70 | 71 | #curl http://localhost:8080/ready 72 | #curl -X POST -H "Content-Type: application/json" -d '{"text": "when is the next flight to new york"}' http://localhost:8080/intent -------------------------------------------------------------------------------- /xlm-roberta-large-custom-trained/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "_name_or_path": "xlm-roberta-large", 3 | "architectures": [ 4 | "XLMRobertaForSequenceClassification" 5 | ], 6 | "attention_probs_dropout_prob": 0.1, 7 | "bos_token_id": 0, 8 | "classifier_dropout": null, 9 | "eos_token_id": 2, 10 | "hidden_act": "gelu", 11 | "hidden_dropout_prob": 0.1, 12 | "hidden_size": 1024, 13 | "initializer_range": 0.02, 14 | "intermediate_size": 4096, 15 | "layer_norm_eps": 1e-05, 16 | "max_position_embeddings": 514, 17 | "model_type": "xlm-roberta", 18 | "num_attention_heads": 16, 19 | "num_hidden_layers": 24, 20 | "output_past": true, 21 | "pad_token_id": 1, 22 | "position_embedding_type": "absolute", 23 | "torch_dtype": "float32", 24 | "transformers_version": "4.37.2", 25 | "type_vocab_size": 1, 26 | "use_cache": true, 27 | "vocab_size": 250002 28 | } 29 | -------------------------------------------------------------------------------- /xlm-roberta-large-custom-trained/label_encoder.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MLArtist/intent-detection-using-XLM-Roberta/03ee48c4b0211368b7633ec7aa1a4a310630d513/xlm-roberta-large-custom-trained/label_encoder.pkl --------------------------------------------------------------------------------