"What is a bear?") query_llm(
'\n\nA bear is a large'
This core notebook is intended to do reading and querying from OpenAI api, once you’ve obtained your domain data using the code from police_risk_open_ai.core.crawl
To run OpenAI, you’ll need:
query_llm (prompt, model='text-davinci-003')
Given a prompt, will query OpenAI and return the output
That all works! I can now run nbdev_prepare
to prepare my code to commit.
LLMs don’t know anything about how to conduct risk assessments, so we’re going to make ours “read” the entirety of Authorised Professional Practice. For now I’m mostly copying this OpenAI tutorial. That’s covered in the second notebook, but I’ve scrapped and clean the College of Policing website. You can see that in the other module.
Before we can begin analysis, we need to split our text into tokens
, recognisable chunks of text-data our model will recognise.
That’s it! We’ve converted our entire library to arrays, and you can see each document converted into our series of datapoints. I’ll export that code into a function.
With our embedding process completed, let’s convert them to Numpy arrays.
We’re now back and close to following the tutorial. The approach is actually quite clever: we use the embeddings to find documents most likely to related, and then combined them into a prompt for completion.
create_context (question, df, max_len=1800, size='ada')
Create a context for a question by finding the most similar context from the dataframe
answer_question (df, model='text-davinci-003', question='Am I allowed to publish model outputs to Twitter, without a human review?', max_len=1800, size='ada', debug=False, max_tokens=150, stop_sequence=None)
Answer a question based on the most similar context from the dataframe texts
Context:
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
.
###
It’s also been raining heavily in the night and we have further calls about flooding in the road, so we ring Highways to inform them. I have a little smile to myself as I remember a call in the summer about cars stopping on the M11 because a mother duck and her ducklings were crossing the road. Lunchtime looms. I’m feeling hungry, but that disappears when I take a call from a 16-year-old male, who tells me that he can’t cope any more. He has cut himself with a knife but he doesn’t want to die. His sister has just had a baby. This goes on an emergency straight away, and officers are dispatched within three minutes. I have to talk to him about anything I can to distract him from his misery – luckily, I am good at small talk! Officers arrive and I feel relief as I can hang up the phone. COVID-19 has really affected Essex this year. People are low and weary. You can hear it in their voices. The number of mental health incidents has gone through the roof, and even the force control room team is quieter. Because of the onset of lockdown restrictions, more calls are coming in from the public reporting their neighbours for flouting the rules: 'We’re following the rules, why don’t they? What makes them think they are special?' Gone are the past calls about drunken people leaving the pub. Instead, we have members of the public who are tired of being tied to the house and resentful of those who ignore the restrictions. After lunch, we receive a flurry of calls. There’s a domestic, involving a woman who tells me that ‘he didn’t mean to hit me, he loves me’. I spend time with this caller. There are three horses in the road. A driver has hit a dog and is upset, so I reassure him it wasn’t his fault. It gets busier. Essex is up and running but I am not. I feel tired but this is my job, so I make sure that nobody will hear it in my voice. Finally, it’s time to go home and hang up the headset for another day. I tend not to reflect on my day too much, so I can have some time to myself. There is no typical day in the control room.
###
The vessel is identified as a rigid-hull inflatable boat (RHIB), which has four people on board wearing foul-weather gear and balaclavas. It appears to still have half a load of bales suspected to contain cannabis resin, wrapped in their distinctive blue and light brown hessian (approximately ¾ of a ton in total). Blue police beacons are engaged and the vessel has been repeatedly signalled to stop, but continues to carry out manoeuvres in an attempt to gain distance. The sea spray is cold and strikes the flesh like pins and needles. After a few minutes, which feel like an eternity, the pursuit is discontinued at the 3NM limits of territorial waters. CAD are informed and requested to inform Spanish Guardia Civil of the vessel’s last known speed and heading. No doubt it will return that night to attempt to unload its remaining cargo. I monitor the area and one of the crew observes something floating in the water. It is suspected to be a bale of cannabis resin, approximately 30-35kg in weight. It is retrieved and found to be in a good state with no marine growth. It is unclear whether it fell off the vessel recently pursued or belongs to a previous incident. The area is searched but nothing more is found. I return to GGMS, where I conduct a debrief. The bale is processed and conveyed to a police station for secure storage. I then complete the necessary paperwork, while the crew slip a zodiac out from the water, which was linked to the recovery of five North African migrants from the sea the previous day, and place the vessel on land. We continue with the mundane but necessary yard and vessel maintenance work. We grab a bite to eat, chat about the morning pursuit and joke about our recent mishaps. The work can be intense but we always manage to fill it with laughter. It’s now 2pm. The afternoon crew arrive. I give them a brief and handover. I then deploy on our training RHIB. As a qualified police instructor, I carry out powerboat training drills for the junior crew member. It reminds me of my early days at the helm and I enjoy passing on the knowledge. At 3.30pm, I return to base and carry out a debrief on the day’s activities. It’s the end of the shift. Let’s see what the next day brings – maybe another encounter with that RHIB.
###
Change to the order of the documents.
###
.police.uk news views. News & views | College of Policing Sorry, you need to enable JavaScript to visit this website. Skip to content Jump to search Menu Secondary navigation About us News & views Contact us Search Search Main navigation Policing guidance Research Career & learning Support for forces Ethics Breadcrumb Home News & views News & views On this page All news Category: - Any -EventGoing equippedListicleBriefExplainerCase studyConsultationNewsViews Sort by: Most recentLess recent 13 March 2023 Bursary scheme 2023 – applications now open News Applications for higher education funding are open and close on Monday 3 April.
###
Updated 26 July 2022 Brief UK and Switzerland – agreement on police cooperation Treaty to strengthen police cooperation between law enforcement authorities in both countries Published 24 March 2022 Case study Director of intelligence – a day in the life There is no such thing as a typical day in any policing role and the director of intelligence is no different Published 30 July 2021 Case study Head of intelligence analysis – a day in the life A key senior role in the analysis side of the intelligence job family Published 30 July 2021 Case study Intelligence manager – a day in the life Overseeing the management, development and collection of intelligence from various sources Published 30 July 2021 Case study Intelligence unit supervisor – a day in the life Leading a team of intelligence officers to gather, develop and disseminate intelligence in support of local and national crime investigations Published 30 July 2021 Case study Senior intelligence analyst – a day in the life Managing an analytical team or a specific area of business within the analytical function Published 30 July 2021 Case study Intelligence support officer – a day in the life Providing information and data management and broad administrative support as part of an intelligence unit Published 30 July 2021 Case study Intelligence officer – a day in the life Managing dissemination of gathered intelligence to support reactive, proactive and/or crimes in action and providing advice on appropriate tactical options to support policing priorities Published 30 July 2021 Case study Researcher in intelligence – a day in the life Using a wide variety of sources to assess and evaluate information – they can then advise on the creation of intelligence products used to support decision-making at a strategic, tactical and/or operational level Published 30 July 2021 Case study Intelligence analyst – a day in the life Providing expertise through the development and use of analytical products to help make decisions at a strategic, tactical and operational level Published 30 July 2021 Case study Using intelligence skills to target criminals ethically and proportionately A role where it's important to keep on top of your continuing professional development and learn from research and analysis colleagues Published 5 November 2020 Looking for more on this topic? Try searching Intelligence Was this page useful? Yes No Do not provide personal information such as your name or email address in the feedback form.
"I don't know."
answer_question(df, question="What are the most important factors to consider when searching for a missing person?", debug=True)
Context:
Very detailed information and a lifestyle profile will be needed in high-risk cases consider taking a full statement from the person reporting the missing person as well as any other key individuals (for example, the last person to see them) conduct initial searches of relevant premises, the extent and nature of the search should be recorded (see Search) consider seizing electronic devices, computers, and other documentation, (for example, diaries, financial records and notes) and obtain details of usernames and passwords obtain photos of the missing person; these should ideally be current likeness of the missing person and obtained in a digital format obtain details of the individual’s mobile phone and if they have it with them; if the missing person has a mobile phone arrange for a TextSafe© to be sent by the charity, Missing People obtain details of any vehicles that they may have access to and place markers on relevant vehicles on the PNC without delay consider obtaining any physical evidence of identity such as fingerprints or DNA samples in accordance with Code of Practice (2009) Collection of Missing Persons Data. confirm if the person has taken their passport, (consider prompt circulation if it is deemed likely the individual may leave the country (This is particularly important where there are concerns that an individual has been radicalised and is intending to travel abroad, see National Ports Office – Heathrow) make all immediate relevant enquiries and take immediate actions in order to locate the missing person consider the need for specialist officers or resources, for example, force helicopters, dogs, financial investigation officers upload the missing person report circulate details of the missing person on local information systems and to relevant local partners, for example, hospitals, ambulance service, taxi and bus firms It is important for an individual (who has responsibilities/concerns for the missing person) to be identified who can act as the point of contact for the police. The police will agree with the individual/family when they will next be contacted. This person should be provided with a call reference number and given details of how to contact the police with any further information they have about the case or if they would like to receive an update. An assessment must be made of the level of support required for the family, residential worker or foster carer and consideration should be given to appointing a family liaison officer. Information should then be provided regarding additional organisations that may be able to assist or support them.
###
It is also important to record the name and contact details of the person who gave that information and when this happened. Missing people may be at risk of harm resulting from factors such as: an inability to cope with weather conditions being the victim of violent crime risks relating to non-physical harm, for example, the people they are with, the places or circumstances they are in For further information see Mental Vulnerability and illness: Vulnerability assessment framework and Vulnerability-related risk guidelines. Assessing risk levels and taking action The missing persons process chart and risk table can assist officers to assess the risk level and appropriate actions that should be assigned to each case. This is a framework to assist practitioners in making operational decisions. Each case requires individual assessment and decision-making. These resources have been developed based on professional expertise and practitioner experience and are available using the following links. Risk assessment table Missing persons process chart It is important to adopt an investigative approach to all reports, ensuring that assumptions are not made about the reasons for going missing. The importance and relevance of risk factors will depend on the circumstances of each case and require investigation to determine if there is a cause for concern. The approach should not be regarded as a mechanical one and police officers should be mindful that the risk assessment is subjective, and that just one factor alone may be considered important enough to prompt an urgent response. For this reason professional experience suggests that a numerical scoring system may not be the most appropriate method of identifying and communicating risk. A decision-making guide should be used to encourage consistency in the application of the process, however, it should only be used as a guide. Other grounds for suspicion, even if intuitive, can be registered by the investigator and officers should be supported in applying the National Decision Model when making these assessments. Accurate record keeping It is essential to accurately record the information received about a missing person. Information that may relate to any perceived risk should be captured at the time of reporting so that it can be used to inform any investigative enquires. This will also prevent duplication of questioning and report writing by investigation officers. Call handlers should be supported by their supervisors to ensure that sufficient time is given to each call to enable all the relevant information to be captured. Detailed missing person reports should be created and appropriate force recording systems and IT systems should be in place to support this process. It is important that the information used and rationale for the risk assessment is clearly recorded.
###
It is also important to record the name and contact details of the person who gave that information and when this happened. Missing people may be at risk of harm resulting from factors such as: an inability to cope with weather conditions being the victim of violent crime risks relating to non-physical harm, for example, the people they are with, the places or circumstances they are in For further information see Mental Vulnerability and illness: Vulnerability assessment framework and Vulnerability-related risk guidelines. Assessing risk levels and taking action The missing persons process chart and risk table can assist officers to assess the risk level and appropriate actions that should be assigned to each case. This is a framework to assist practitioners in making operational decisions. Each case requires individual assessment and decision-making. These resources have been developed based on professional expertise and practitioner experience and are available using the following links. Risk assessment table Missing persons process chart It is important to adopt an investigative approach to all reports, ensuring that assumptions are not made about the reasons for going missing. The importance and relevance of risk factors will depend on the circumstances of each case and require investigation to determine if there is a cause for concern. The approach should not be regarded as a mechanical one and police officers should be mindful that the risk assessment is subjective, and that just one factor alone may be considered important enough to prompt an urgent response. For this reason professional experience suggests that a numerical scoring system may not be the most appropriate method of identifying and communicating risk. A decision-making guide should be used to encourage consistency in the application of the process, however, it should only be used as a guide. Other grounds for suspicion, even if intuitive, can be registered by the investigator and officers should be supported in applying the National Decision Model when making these assessments. Accurate record keeping It is essential to accurately record the information received about a missing person. Information that may relate to any perceived risk should be captured at the time of reporting so that it can be used to inform any investigative enquires. This will also prevent duplication of questioning and report writing by investigation officers. Call handlers should be supported by their supervisors to ensure that sufficient time is given to each call to enable all the relevant information to be captured. Detailed missing person reports should be created and appropriate force recording systems and IT systems should be in place to support this process. It is important that the information used and rationale for the risk assessment is clearly recorded.
'It is important to adopt an investigative approach to all reports, ensuring that assumptions are not made about the reasons for going missing. The importance and relevance of risk factors will depend on the circumstances of each case and require investigation to determine if there is a cause for concern. It is also important to record the name and contact details of the person who gave that information and when this happened. Missing people may be at risk of harm resulting from factors such as: an inability to cope with weather conditions, being the victim of violent crime, and risks relating to non-physical harm, for example, the people they are with, the places or circumstances they are in.'
Now, let’s tweak to answer sergeant exam questions, and see how it does.
answer_sergeant_exam_question (df, question, model='text-davinci-003', max_len=1800, size='ada', debug=False, max_tokens=150, stop_sequence=None)
Answer a question based on the most similar context from the dataframe texts
Let’s answer a question from here https://www.how2become.com/blog/police-sergeants-inspectors-exam/
question = """ Officer Jennings is on his evening patrol. He is just about to finish for the day. As he walks down the street, he is approached by a man named Mark, who claims that he saw a man (named Steven) driving down a road not far from the location. Mark claims that he saw Steven drive into a cyclist, before driving off without stopping. Luckily, the cyclist was unharmed. The cyclist was named Kevin. Mark spoke to Kevin, and discovered that he is a 42 year old man, with a wife and two daughters.
Fifteen minutes later, Officer Jennings manages to stop the car being driven by Steven. He pulls him over to the side of the road, and orders him to step out of the car.
Referring s.6 (5) of the Road Traffic Act 1988, is Officer Jennings within his legal rights to order that Steven takes a preliminary breath test?
A – No. Officer Jennings has no right to tell Steven what he can and can’t do. He should never have stopped Steven in the first place.
B – No. In order for Officer Jennings to do this, an accident must have happened. The fact that Officer Jennings suspects an accident has taken place, does not meet this requirement.
C – Yes. However, the breath test must take place within or close to an area where the requirements for Steven to cooperate, can be imposed.
D – Yes. Officer Jennings can tell Steven to do whatever he wants, as he’s a police officer."""
answer_sergeant_exam_question(df,question)
'B - No. In order for Officer Jennings to do this, an accident must have happened. The fact that Officer Jennings suspects an accident has taken place, does not meet this requirement.'
conduct_risk_assessment (df, question, model='text-davinci-003', max_len=1800, size='ada', debug=False, max_tokens=150, stop_sequence=None)
Answer a question based on the most similar context from the dataframe texts
risk_profile = """John Smith is a 31 year old man who has been missing for 5 hours. He went to work as normal this morning, and has not returned home, and his partner is concerned. There are no signs of foul play, no vulnerabilities. John is in good health, the weather is good, and there are no concerns for his welfare."""
conduct_risk_assessment(df, risk_profile, debug=True)
'Graded as Low risk, because of the below risk factors:\n- John is an adult, and there are no signs of foul play or vulnerabilities\n- He is in good health, and the weather is good\n- There are no concerns for his welfare'
jason_risk_profile = """ Jason is a 15 year old adult male, who has gone missing from his care home in Southwark. His carer has contacted the school, which has said he was not in today.
They that this is not the first time, and that Jason has been seen hanging out with older boys, who may be involved in crime and drugs."""
conduct_risk_assessment(df, jason_risk_profile, debug=True)
Context:
First published 22 November 2016 Updated 15 March 2023 Latest changes Written by College of Policing Missing persons 30 mins read Implications for the UK leaving the European Union are currently under review – please see APP on international investigation for latest available detail on specific areas, for example: Schengen Information System Europol INTERPOL Joint Investigation Teams This section provides additional information to aid the investigation based on the vulnerability of the individual and the circumstances in which they are missing. Missing children Safeguarding young and vulnerable people is a responsibility of the police service and partner agencies (see Children Act 2004). When the police are notified that a child is missing, there is a clear responsibility on them to prevent the child from coming to harm. Where appropriate, a strategy meeting may be held. For further information see: Voice of the child Voice of the child practice briefing Section 11 of the Children Act 2004 Department for Education (2014) Statutory guidance on children who run away or go missing from home or care Children’s Views on being Reported Missing from Care Young people and risky behaviour Children and young people often do not have the same levels of awareness or ability to keep themselves safe as adults. Going missing may indicate that something is wrong in their lives. Many of the children and young people who repeatedly go missing are considered by some to be ‘streetwise’ and able to look after themselves. However, these children may not understand the risk they are exposing themselves to, and should not be treated as low/no apparent risk simply due to their apparent willingness/complicity. Children may put themselves in danger because they may have been abused, neglected or rejected by their families or others and, as a result, they may engage in further risky behaviours, such as: misusing substances committing crimes having risky sexual contacts living on the streets mixing with inappropriate adults Information relevant to the child When a missing person report relates to a looked-after child, it is important to work with all the agencies and carers that have been in regular contact with the child as they may have information about the child that might help to locate them. When a child is missing from care, close engagement with the carers is important.
###
These include children or young people who: go missing – especially on regular occasions from home or care live in a chaotic or dysfunctional family have a history of domestic abuse within the family environment have a history of abuse (including familial child sexual abuse, risk of forced marriage, risk of honour-based violence, physical and emotional abuse and neglect) have experienced or are experiencing problematic parenting have parents who misuse drugs or alcohol have parents with health problems are young carers within the family unit experience social exclusion as a result of poverty have experienced recent bereavement or loss have unsupervised use of social networking chat rooms/sites have mental ill health have social or learning difficulties have low self-esteem or self-confidence are unsure about their sexual orientation or are unable to confide in their family about their sexual orientation misuse alcohol and/or drugs have been or are excluded from mainstream education are involved in gang activity attend school with other young people who are sexually exploited are friends with individuals who are sexually exploited do not have friends in the same age group are being bullied live in care, foster care, hostels and/or bed and breakfast accommodation – particularly when living out of their home area are homeless have associations with gangs through relatives, peers or intimate relationships live in a gang neighbourhood This is not an exhaustive list, nor have the vulnerabilities been listed in order of importance. Children from loving and secure homes can also be victims of sexual exploitation. The characteristics common to all victims are not always their age, ethnicity, disability or sexual orientation, but their powerlessness and vulnerability. Warning signs Despite the increased profile of CSE and improvements in how the police work with partner agencies, CSE cases are still under-reported. The Office of the Children’s Commissioner conducted a two-year inquiry into child sexual exploitation in gangs and groups. Their 2013 report, If only someone had listened, highlights that sexually exploited children are not always identified even when they show signs of being victims. Numerous warning signs were identified in the Office of the Children’s Commissioner 2012 interim report, I thought I was the only one, the only one in the world, which can indicate that a young person is being forced or manipulated into sexual activity and is a victim of sexual exploitation. Practitioners need to be aware of these warning signs and recognise that a victim does not have to exhibit all of the warning signs to be a victim of sexual exploitation.
###
Staff should tell the detainee that she can ask to see the carer at any time. Forces must implement policies and procedures to ensure that all girls who are detained and in custody are under the care of a woman. For further information, see PACE Code C, section 3.20A. Transporting children and young people Children and young persons under the age of 18 are not allowed to associate with adult detainees while being detained, conveyed to and from court or waiting to be so conveyed. An exception to this is permitted in accordance with the Children and Young Persons Act 1933 section 31, where the young person is jointly charged with an adult or relative. Officers should make arrangements to prevent association when the child or young person is: detained in a police station being conveyed to or from any criminal court attending court Children and young people should not be carried in a vehicle with adult detainees unless the vehicle has been designed and built to carry them separately and simultaneously. Vehicles that are available for this specific purpose are authorised under the 2011 Prisoner Escort and Custody Services’ contract arrangements. Appropriate adults Forces should establish policies and protocols to provide access to appropriate adults for young persons in police custody. Local YOTs have a statutory responsibility to ensure that an appropriate adult service is provided for children and young people, whether they provide the service themselves or contract a voluntary or private sector agency to do so on their behalf. It is the responsibility of the appropriate adult provider to work with the local force to develop policies and protocols to ensure there is effective provision of appropriate adult services in line with Youth Justice Board (2014) case management guidance. This guidance makes it clear that the appropriate adult service should operate out of hours as well as during standard working hours. All appropriate adults, custody managers, custody officers and staff must be aware of their role as defined by PACE, and also of any agreed local policies, protocols or service level agreements for providing appropriate adults. For further information, see PACE and section 38 of the Crime and Disorder Act 1998. See also the Youth Justice Board’s (YJB) National Standards for Youth Justice Services. The YJB and National Appropriate Adult Network have also published joint guidance and advice on appropriate adult services. When should an appropriate adult be contacted? Detention can be very stressful so it is important that an appropriate adult attends as soon as is practicable to minimise the amount of time the child or young person spends in detention.
'Graded as Medium risk, because of the below risk factors:\n- Jason is a 15 year old adult male, who has gone missing from his care home in Southwark\n- This is not the first time he has gone missing\n- He has been seen hanging out with older boys, who may be involved in crime and drugs'
The model works. I’m happy with it. So let’s tie it into a function we can deploy as a web app.
machine_risk_assessment (question, df, model='text-davinci-003', max_len=1800, size='ada', debug=False, max_tokens=150, stop_sequence=None)
Answer a question based on the most similar context from the dataframe texts
about_yannik = """ Yannik is a 15 year old boy. He has recently been down, and was reported missing by his parents as he did not return home from school today.
His friends are worried he may be depressed, and when he apparently told one a few days ago 'if it doesn't get any better, I'm going to end it soon'
"""
yannik_answer, yannik_context = machine_risk_assessment(about_yannik, df)
yannik_answer
'Graded as High risk, because of the below risk factors: \n- Yannik is a 15 year old boy who has been reported missing by his parents\n- His friends are worried he may be depressed\n- He has expressed suicidal ideation to one of his friends'
It works!
Let’s now add the ChatAPI rather than auto-completion, which should improve performance and cost
create_chat_assistant_content (question, df, max_len=2800, size='ada')
Create a context for a question by finding the most similar context from the dataframe
create_chat_assistant_question (question)
copbot_chat_risk_assessment (individual_circumstances, df, return_context=False, debug_mode=False)
Takes a user input string about the individual circumstances of a missing person, and returns a risk assessment
df = pd.read_parquet('processed/embeddings.parquet')
jason_risk_profile = """Jason is a 15 year old adult male, who has gone missing from his care home in Southwark. His carer has contacted the school, which has said he was not in today.
They that this is not the first time, and that Jason has been seen hanging out with older boys, who may be involved in crime and drugs."""
copbot_chat_risk_assessment(jason_risk_profile, df, debug_mode=True)
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Graded as medium risk, because of the below risk factors:\n- The person is a minor and vulnerable\n- The person has been seen hanging out with older boys who may be involved in crime\n\nGiven these factors, there is a likelihood of harm to the subject as well as the public, especially if he is being influenced by the older boys he has been seen with. Therefore, appropriate immediate action is required to locate and ensure the safety of Jason. Additionally, it may be necessary to investigate the activities of the care home to establish how he was allowed to go missing repeatedly.",
"role": "assistant"
}
}
],
"created": 1680974755,
"id": "chatcmpl-736bzcixDS24mIRSX3ncHR9ARrknH",
"model": "gpt-3.5-turbo-0301",
"object": "chat.completion",
"usage": {
"completion_tokens": 116,
"prompt_tokens": 2706,
"total_tokens": 2822
}
}
'Graded as medium risk, because of the below risk factors:\n- The person is a minor and vulnerable\n- The person has been seen hanging out with older boys who may be involved in crime\n\nGiven these factors, there is a likelihood of harm to the subject as well as the public, especially if he is being influenced by the older boys he has been seen with. Therefore, appropriate immediate action is required to locate and ensure the safety of Jason. Additionally, it may be necessary to investigate the activities of the care home to establish how he was allowed to go missing repeatedly.'